Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Prerequisites

ConceptsImportanceNotes
MatplotlibNecessary
CartopyNecessary
  • Time to learn: 10 minutes


Data

The first piece of data visualization is the data!

Let’s generate some dummy data to work with:

Figure

The figure is the object that contains your entire visualization. Creating a figure tends to be the first step in plotting, even if it doesn’t currently show anything:

<Figure size 950x800 with 0 Axes>

Axis

We then add axes to our plot. You can add multiple axes to one plot in order to produce subplots, or just one. Axes will automatically inherit their limits from the data plotted, or can be manually set.

<Figure size 950x800 with 1 Axes>

Plot

Adding the data to the figure can be done through several different plot types: line, contour, bar, histogram. Here we use two line plots:

<Figure size 950x800 with 1 Axes>

Titles and Labels

Titles and labels are important for indicating what the figure is plotting. It is a good idea to include relevant units in your axis labels.

<Figure size 950x800 with 1 Axes>

Legends

If you’re plotting multiple lines of data, it’s a good idea to include a legend. Here is how you call or point to the legend:

<Figure size 950x800 with 1 Axes>

Colorbars

While legends are more appropriate for line or bar plots, colorbars are most commonly used for contour plots and sometimes to apply a third level of dimension to a scatter plot.

Let’s shift our example to better demonstrate a colorbar by workign with a filled contour plot:

Loading...
<Figure size 950x800 with 2 Axes>

Annotations

Additional annotations allow you to specify some text and a location to indicate almost anything.

Here we use GeoCAT-viz to add annotations to the maxima in a contour plot:

<Figure size 950x800 with 2 Axes>

Summary

There are several key elements to a Python plot and knowing what they are called is instrumental to begin your journey for further customization.

What’s next?

Next up, the specialty plots called Taylor Diagrams.

Resources and references