Line Plot using Matplotlib - Machine Learning Tutorials, Courses and Certifications

Line Plot using Matplotlib - Machine Learning Tutorials, Courses and Certifications

Machine Learning November 19, 2021 Data Science Comments Off on Line Plot using Matplotlib 6,325 Views

To plot a line plot in Matplotlib, you use the generic plot() function from the PyPlot instance. There’s no specific lineplot() function – the generic one automatically plots using lines or markers.

Alternatively, we could’ve completely omitted the x axis, and just plotted y. This would result in the X-axis being filled with range(len(y)):

You may be wondering why the x-axis ranges from 0-4 and the y-axis from 0-50. If you provide a single list or array to the plot() command, matplotlib assumes it is a sequence of y values, and automatically generates the x values for you. Since python ranges start with 0, the default x vector has the same length as y but starts with 0. Hence the x data are [0,1,2,3,4].

The following color abbreviations are supported: character color

Documentation: https://matplotlib.org/stable/gallery/lines_bars_and_markers/linestyles.html

Documentation: https://matplotlib.org/stable/api/markers_api.html

tight_layout automatically adjusts subplot params so that the subplot(s) fits in to the figure area. This is an experimental feature and may not work for some cases. It only checks the extents of ticklabels, axis labels, and titles.

Turn on xkcd sketch-style drawing mode. This will only have effect on things drawn after this function is called.

Recommended articles