Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As you have noticed, <code>xscale</code> and <code>yscale</code> does not support a simple linear re-scaling (unfortunately). As an alternative to Hooked's answer, instead of messing with the data, you can trick the labels like so:</p> <pre><code>ticks = ticker.FuncFormatter(lambda x, pos: '{0:g}'.format(x*scale)) ax.xaxis.set_major_formatter(ticks) </code></pre> <p>A complete example showing both x and y scaling:</p> <pre><code>import numpy as np import pylab as plt import matplotlib.ticker as ticker # Generate data x = np.linspace(0, 1e-9) y = 1e3*np.sin(2*np.pi*x/1e-9) # one period, 1k amplitude # setup figures fig = plt.figure() ax1 = fig.add_subplot(121) ax2 = fig.add_subplot(122) # plot two identical plots ax1.plot(x, y) ax2.plot(x, y) # Change only ax2 scale_x = 1e-9 scale_y = 1e3 ticks_x = ticker.FuncFormatter(lambda x, pos: '{0:g}'.format(x/scale_x)) ax2.xaxis.set_major_formatter(ticks_x) ticks_y = ticker.FuncFormatter(lambda x, pos: '{0:g}'.format(x/scale_y)) ax2.yaxis.set_major_formatter(ticks_y) ax1.set_xlabel("meters") ax1.set_ylabel('volt') ax2.set_xlabel("nanometers") ax2.set_ylabel('kilovolt') plt.show() </code></pre> <p>And finally I have the credits for a picture:</p> <p><a href="https://i.stack.imgur.com/IdZsD.png" rel="noreferrer"><img src="https://i.stack.imgur.com/IdZsD.png" alt="Left: ax1 no scaling, right: ax2 y axis scaled to kilo and x axis scaled to nano"></a></p> <p>Note that, if you have <code>text.usetex: true</code> as I have, you may want to enclose the labels in <code>$</code>, like so: <code>'${0:g}$'</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload