When plotting data involving large numbers, it's common to encounter an axis with relative shift, resulting in ticks with a fractional component accompanied by a magnitude indicator (e.g., " 1e3"). This can be unintuitive, especially when dealing with smaller datasets.
To resolve this issue, Matplotlib provides a straightforward solution that involves configuring the major formatter object on the x-axis:
1 2 3 |
|
By setting useOffset to False, the formatter is instructed to display the tick values without the relative shift. This results in cleaner axis labels, as seen in the following code:
1 2 3 |
|
This code will produce an axis with tick values like this:
1 |
|
Alternatively, in more recent versions of Matplotlib (1.4 ), the default behavior can be modified globally via the axes.formatter.useoffset rcparam:
1 |
|
The above is the detailed content of How to Eliminate Relative Shift in Matplotlib Axis Labels?. For more information, please follow other related articles on the PHP Chinese website!