LearnWave
Learn it. Master it.

Plotting Data using Matplotlib

Customising plots

Add customisations to a pyplot line chart.

A chart needs labels to make sense. Pyplot functions to customise it:

  • plt.xlabel() and plt.ylabel(): labels for the axes;
  • plt.title(): the chart's title;
  • plt.grid(True): adds grid lines;
  • plt.xticks(ticks, labels) and plt.yticks(): set where the tick marks go and what they say;
  • plt.legend(): a key, needed when several datasets are plotted together.

Parameters of plot() change how the line looks:

  • marker: a symbol at each data point, such as 'o' (circle), 'd' (diamond) or 's' (square); markersize=10 sets its size;
  • color: a name like 'green', or a code like 'g' (green), 'r' (red), 'b' (blue), 'k' (black);
  • linewidth=2: thickness of the line;
  • linestyle: 'solid', 'dotted', 'dashed' or 'dashdot'.

Example: plt.plot(days, temp, marker='o', color='r', linestyle='dashed') draws a red dashed line with a circle at each point. Every chart needs a title and axis labels.

Title and labels on every chart.

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.