WeCodeAcademy

Your First Chart

A chart turns a column of numbers into a shape the eye can read in a second. In Python the standard tool is matplotlib, and its plotting module is nearly always imported as plt.

Every chart has two parts: a figure (the whole picture, like a sheet of paper) and one or more axes (the area where the data is drawn, with its x and y scales). fig, ax = plt.subplots() creates both. You then call methods on ax, such as ax.plot(x, y), and finish with plt.show() to display the result.

Press Run on the example. The chart appears under the code.

Examplepython
Open in editor »
Quick check

What does `fig, ax = plt.subplots()` create?

Your turn: write the code

Draw a line chart of temps against days on ax, then print the y values of the line it drew (use ax.get_lines()[0].get_ydata().tolist()).

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.