O'Reilly logo

matplotlib Plotting Cookbook by Alexandre Devert

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Controlling tick labeling

Tick labels are coordinates in the figure space. Although it makes sense for a fair number of cases, it is not always adequate. For instance, let's imagine a bar chart that shows the median income of 10 countries. We would like to see the names of the countries under each bar, rather than the coordinates of the bars. For a time series, we would like to see dates rather than some abstract coordinate. matplotlib provides a comprehensive API precisely for this. In this recipe, we will see how to control tick labeling.

How to do it...

Using the standard matplotlib ticks API, setting ticks for a bar chart (or any other kind of graphics) is done as follows:

import numpy as np import matplotlib.ticker as ticker import matplotlib.pyplot ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required