![]() ![]() Time series is the collection of data values listed or indexed in order of time. Read: Matplotlib subplot tutorial Python plot multiple lines time series Python plot multiple lines with the different y-axis # Define data values by creating a Dataframe using a n-dimensional listĭf = pd.DataFrame(,, , Let’s prepare the data for the example, here a Dataframe is created with 4 columns and 7 rows. ![]() So, in such cases, you can use a for loop to plot the number of lines by using the () function only once inside the loop, where x and y-axis parameters are not fixed but dependent on the loop counter. If there is a case where, there are several lines that have to be plotted on the same graph from a data source (array, Dataframe, CSV file, etc.), then it becomes time-consuming to separately plot the lines using () function. Read: Python NumPy Array Python plot multiple lines for loop Python plot multiple lines from dataframe You can specify the color parameter as a positional argument (eg., ‘c’ –> means cyan color ‘y’ –> means yellow color) or as keyword argument (eg., color=’r’ –> means red color color=’green’ color=’#B026FF’ –> means neon purple color). You can either specify the color by their name or code or hex code enclosed in quotes. There are various colors available in python. You have to specify the value for the parameter color in the plot() function of matplotlib.pyplot. You can specify the color of the lines in the chart in python using matplotlib. Read: How to install matplotlib Python plot multiple lines of different color At the end, () function is called to display the graph containing the properties defined before the function. Then () function is called twice with different x, y parameters to plot two different lines. In the above example, the data is prepared as lists as x, y, z. Python plot multiple lines on the same graph # Plot another line on the same chart/graph So, open up your IPython shell or Jupiter notebook, and follow the code below: # Importing packages Let’s plot a simple graph containing two lines in python.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |