LearnWave
Learn it. Master it.

Plotting Data using Matplotlib

Plotting with Matplotlib

Plot, show and save a line chart with pyplot.

Data visualisation means showing data in a graphical or pictorial form, so that we can see variation and relationships at a glance, which is hard to do from a table of numbers.

Python's Matplotlib library draws charts. Install it with pip install matplotlib, and import its plotting module with import matplotlib.pyplot as plt (plt is just a short alias; any name would work).

The basic steps:

  • plt.plot(x, y) draws a line chart by default, with x values on the horizontal axis and y values on the vertical axis;
  • plt.show() displays the figure;
  • plt.savefig('chart.png') saves the figure as an image file.

Pyplot has functions for other kinds of chart too: bar() (bar chart), boxplot(), hist() (histogram), pie() and scatter(). plot, then show.

plot, then show.

Practise this lesson

Questions that get harder as you improve, a Tutor that helps without giving the answer away, and progress you can see. Free for every learner.

No account, no email address. Opens the real product.