Decide what the eye should see
Styling is not decoration. Every line, grid, spine, and label competes for attention. Keep the data prominent, make labels easy to read, and remove chart furniture that does not help the comparison.
Python
A quieter frame around the data
Output
Press Run to execute this cell. The first run downloads Python; later runs reuse the session.
Use color with purpose
Color can separate series, encode a category, or highlight one observation. It should not be the only difference between series. Pair hue with markers, line styles, or direct labels so the chart still works in grayscale.
Python
Distinct colors and distinct markers
Output
Press Run to execute this cell. The first run downloads Python; later runs reuse the session.
Annotate the point that matters
A direct annotation explains an unusual point where it appears. ax.annotate connects text at xytext to a data coordinate at xy. Use it for a peak, a gap, or a threshold rather than making the reader hunt through the caption.
Python
A label connected to the data
Output
Press Run to execute this cell. The first run downloads Python; later runs reuse the session.
Annotation coordinates are in data units for both xy and xytext by default. If the text lands off the axes, adjust the offset or use axes-fraction coordinates deliberately.
Reuse a style without surprises
Matplotlib ships with named styles. plt.style.use changes the active settings globally; plt.style.context applies a style only inside a block. The context manager is safer when one figure needs a different visual system.
Python
Apply a style to one figure
Output
Press Run to execute this cell. The first run downloads Python; later runs reuse the session.
A style changes defaults, not your data. Still provide titles, units, and legends; a theme cannot supply the meaning of the chart.
Export a chart worth keeping
Use savefig with a vector format such as PDF or SVG for reports, or PNG at a deliberate DPI for the web. bbox_inches="tight" removes excess whitespace. In this runner, open figures are captured automatically.
Python
The figure captured by this runner
Output
Press Run to execute this cell. The first run downloads Python; later runs reuse the session.
Practice
Make it stick
Run the tests as often as you like. Hints and the solution are available when you need them.
Exercise
Plot signups with color "#2563eb", marker "o", and line width 2. Add an annotation containing the word "Peak" at the maximum value. Set the title to "Monthly signups" and hide the top and right spines.
Your solution
ReadyResults
Run the tests to check your solution. The first run downloads Python; later runs reuse the session.
Quiz
Check your understanding
Lesson progress