import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { const title = 'Horizontal List'; return MaterialApp( title: title, home: Scaffold( appBar: AppBar( title: const Text(title), ), body: Container( margin: const EdgeInsets.symmetric(vertical: 20.0), height: 200.0, child: ListView( // This next line does the trick. scrollDirection: Axis.horizontal, children:[ Container( width: 160.0, color: Colors.red, ), Container( width: 160.0, color: Colors.blue, ), Container( width: 160.0, color: Colors.green, ), Container( width: 160.0, color: Colors.yellow, ), Container( width: 160.0, color: Colors.orange, ), ], ), ), ), ); } } Printing the list has been dealt many times. But sometimes we need a different format to get the output of list. This also has application in getting a transpose of matrix. Printing list vertically also has application in web development. Lets discuss certain ways in which this task can be achieved. Method #1 : Using Naive Method The naive method can be used to print the list vertically vis. using the loops and printing each index element of each list successively will help us achieve this task. Python3
The original list is : [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 100 The original list is : [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 101 The original list is : [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 102 The original list is : [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 103 The original list is : [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 104 The original list is : [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 103 The original list is : [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 106 The original list is : [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 107 The original list is : [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 104 The original list is : [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 103 The original list is: [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 100 The original list is : [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 103 The original list is: [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 102 The original list is : [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 107 The original list is: [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 102 The original list is : [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 103 The original list is: [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 106 The original list is : [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 103 The original list is: [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 108 The original list is: [[1, 4, 5], [4, 6, 8], [8, 3, 10]] 1 4 8 4 6 3 5 8 109 Matplotlib is a popular python library used for plotting, It provides an object-oriented API to render GUI plots. Plotting a horizontal line is fairly simple, The following code shows how it can be done. Making a single vertical lineMethod #1: Using () This function adds the vertical lines across the axes of the plot
Python3
Output: Method #2: Using vlines() matplotlib.pyplot.vlines() is a function used in the plotting of a dataset. In matplotlib.pyplot.vlines(), vlines is the abbreviation for vertical lines. What this function does is very much clear from the expanded form, which says that function deals with the plotting of the vertical lines across the axes.
Python3
Method #3: Using plot() The plot() function in pyplot module of matplotlib library is used to make a 2D hexagonal binning plot of points x, y.
Python3
Plotting multiple lines with the legend
The below methods can be used for plotting multiple lines in Python. Method #1: Using () Python3
|