Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove relative shift in matplotlib axis

Tags:

When I try to do a plot against a range with big enough numbers I get an axis with relative shift for all the ticks. For example:

plot([1000, 1001, 1002], [1, 2, 3]) 

I get these ticks on axis of abscissas:

0.0     0.5     1.0     1.5     2.0                                +1e3 

The question is how to remove +1e3 and get just:

1000.0  1000.5  1001.0  1001.5  1002.0 
like image 605
Igor Mikushkin Avatar asked Aug 07 '12 23:08

Igor Mikushkin


People also ask

How do I get rid of Xticks in MatPlotLib?

Matplotlib removes both labels and ticks by using xticks([]) and yticks([]) By using the method xticks() and yticks() you can disable the ticks and tick labels from both the x-axis and y-axis. In the above example, we use plt.

How do I shift axes in MatPlotLib?

MatPlotLib with PythonSet the figure size and adjust the padding between and around the subplots. Create x and y data points using numpy. Plot the x and y data points for the original curve. Plot the shifted graph, in the range of (1, 1+len(y)) with y data points.

What does PLT axis () do?

The plt. axis() method allows you to set the x and y limits with a single call, by passing a list which specifies [xmin, xmax, ymin, ymax] : In [11]: plt.

How do I save a high resolution PNG in Python?

We can set the dpi value to get a high-quality image. Using the saving() method, we can save the image with format=”png” and dpi=1200. To show the image, use the plt. show() method.


1 Answers

plot([1000, 1001, 1002], [1, 2, 3]) gca().get_xaxis().get_major_formatter().set_useOffset(False) draw() 

This grabs the current axes, gets the x-axis axis object and then the major formatter object and sets useOffset to false (doc).

In newer versions (1.4+) of matplotlib the default behavior can be changed via the axes.formatter.useoffset rcparam.

like image 128
tacaswell Avatar answered Sep 21 '22 10:09

tacaswell