LearnWave
Learn it. Master it.

Plotting Data using Matplotlib

Pandas plot: line and bar charts

Use the plot method of a DataFrame to draw line and bar charts and customise them.

Pandas Series and DataFrames have their own plot() method, built on Matplotlib: s.plot() or df.plot().

The kind parameter chooses the chart: 'line' (the default), 'bar', 'barh' (horizontal bars), 'hist', 'box', 'area', 'pie' and 'scatter'.

Line plots show trends over time. By default, the DataFrame's index goes on the x axis. To show meaningful labels, like day names, use plt.xticks(ticks, df.Day).

Bar charts are best for comparing values. df.plot(kind='bar', x='Day') puts the Day column on the x axis; without x=, the index is used.

You can still use Pyplot functions like plt.title() and plt.xlabel() with a pandas plot. Parameters like color, edgecolor, linewidth, linestyle and marker customise it, and a legend appears by default. Line for trends, bar for comparison.

Line for trends, bar for comparison.

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.