Hi again,

unfortunately, the proposed solution breaks a second y-axis. Attached
is a script which demonstrates the problem in the third figure. The
second axis should be half of the first one.


import pylab
import scipy

pylab.close('all')

##------------------------------------------------------------------------------
## matplotlib.pyplot / pylab
x = scipy.arange(100)
y = scipy.rand(100) + 1000006

pylab.figure()
pylab.plot(x,y)
pylab.grid()

#pylab.ticklabel_format(useOffset=1000000, axis='y')
pylab.ticklabel_format(useOffset=False, axis='y')

##------------------------------------------------------------------------------
## matplotlib
fig = pylab.figure(figsize=(8,6))
ax = fig.add_subplot(111)
ax.plot(x,y)
ax.grid()

ax.ticklabel_format(useOffset=1000000, axis='y')
#ax.ticklabel_format(useOffset=False, axis='y')

##------------------------------------------------------------------------------
## matplotlib twinx()
fig = pylab.figure(figsize=(8,6))
ax1 = fig.add_subplot(111)
ax2 = ax1.twinx()
ax1.plot(x,y)
ax1.grid()

## automatically update ylim of ax2 when ylim of ax1 changes:
def update_ax2(ax1):
  y1, y2 = ax1.get_ylim()
  ## modify the limits
  ax2.set_ylim((y1/2., y2/2.))
  ax2.figure.canvas.draw()
ax1.callbacks.connect("ylim_changed", update_ax2)

ax1.ticklabel_format(useOffset=False, axis='y')

##------------------------------------------------------------------------------
pylab.show()




2011/3/10 Daniel Mader <danielstefanma...@googlemail.com>:
> Hi Ben,
>
> thanks a lot, this really helpes in the simple example, I'll try to
> find out how to use it in the complex script. It seems 1.0.0 is recent
> enough for this!
>
> Thanks again,
> Daniel
>
> 2011/3/10 Benjamin Root <ben.r...@ou.edu>:
>>
>>
>> On Thu, Mar 10, 2011 at 4:54 AM, Daniel Mader
>> <danielstefanma...@googlemail.com> wrote:
>>>
>>> Hi,
>>>
>>> is it possible to change the default y-axis scaling so that the
>>> ticks/label are not with respect to the large offset?
>>>
>>> For example:
>>>
>>> import scipy
>>> import pylab
>>>
>>> x = scipy.arange(100)
>>> y = scipy.rand(100) + 1000006
>>>
>>> pylab.figure()
>>> pylab.plot(x,y)
>>> pylab.grid()
>>>
>>> pylab.show()
>>>
>>> This gives the y-limits as (0,1) with respect to 1000006. This makes
>>> it very hard to read. I'd like to be able to configure this manually.
>>>
>>> Thanks in advance,
>>> Daniel
>>>
>>
>> I tried to fix matplotlib to be smarter about choosing the offset value a
>> while back, but I couldn't come up with something that worked well in the
>> general case.  You can manually turn it off completely, and have the full
>> value displayed (or even manually set the offset value).  If you have a very
>> recent matplotlib:
>>
>> import matplotlib.pyplot as plt
>> import numpy as np
>>
>> x = np.arange(100)
>> y = np.random.rand(100) + 1000006
>>
>> plt.figure()
>> plt.plot(x, y)
>> plt.grid()
>> plt.ticklabel_format(useOffset=1000000, axis='y')
>>
>> plt.show()
>>
>> Or you can turn it off by setting useOffset to False.
>>
>> If you don't have a recent enough matplotlib, you can turn it off completely
>> by doing something like this:
>>
>> import matplotlib.pyplot as plt
>> import numpy as np
>> from matplotlib.ticker import ScalarFormatter
>>
>> x = np.arange(100)
>> y = np.random.rand(100) + 1000006
>>
>> fig = plt.figure()
>> ax = fig.gca()
>> ax.plot(x, y)
>> ax.grid()
>> ax.yaxis.set_major_formatter(ScalarFormatter(useOffset=False))
>>
>> plt.show()
>>
>>
>> I hope this helps!
>> Ben Root
>>
>>
>



-- 
Zugallistr. 11/14
5020 Salzburg
M_at +43 699 10 54 54 53
T_at +43 662 841635
M_de +49 179 2300317
E danielstefanma...@googlemail.com

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to