

The y-axis can also be shared if the second series has the same scale, or if the scales are different you can also plot on two different y-axes. Generally used to show lines that share the same axis, for example, lines sharing the x-axis. Matplotlib also allows you to plot multiple lines in the same chart. You can use pyplot’s xlabel() and ylabel() functions to set axis labels and use pyplot’s title() function to set the title for your chart. Matplotlib’s pyplot comes with handy functions to set the axis labels and chart title. Refer to the official documentation for a complete list of format string combinations. If you want a line chart with * markers and dashed line, use *- as your format string. In the format string 'o-g', o denotes circular marker, - is for a solid line, and g is for the color green. The order can also change (like, ') but its parsing can be ambiguous. They are “abbreviations for quickly setting basic line properties”.Ī format string is made of three parts: '' with each of them being optional. In the above example, in addition to the values for the x-axis and y-axis, we provided a third argument, 'o-g'. We have also add circular markers to show each datapoint.

In the above above example, you can see that we have Year as the x-axis label, Employees as the y-axis label and Employee Growth at A as the chart title. Let’s add axis labels, chart title, and markers for data points on the chart to make it more informative. Matplotlib allows a number of different formatting options on your chart. The line chart that we got in the previous example is very simple without much formatting. The chart shows an upward trend in the employee count at the company A year on year. You can see in the above chart that we have the year on the x-axis and the employee count on the y-axis. One list has the employee count while the other has the respective years. We have the data on the number of employees of a company, A year on year, and want to plot it on a line chart using matplotlib. Plot a line chart with default parameters Let’s look at some of the examples of plotting a line chart with matplotlib. Here, x_values are the values to be plotted on the x-axis and y_values are the values to be plotted on the y-axis. The following is the syntax to plot a line chart: import matplotlib.pyplot as plt In matplotlib, you can plot a line chart using pyplot’s plot() function. Line charts are great to show trends in data by plotting data points connected with a line.
#PLOT LINE IN SCATTER PLOT MATPLOTLIB HOW TO#
In this tutorial, we’ll look at how to plot a line chart using Matplotlib. It is quite powerful and comes up with a range of charts that can be highly customized. Matplotlib is a library in Python used for plotting charts.
