On Thu, Apr 12, 2012 at 5:20 PM, Benjamin Root <ben.root@ou.edu> wrote:


On Thu, Mar 29, 2012 at 5:53 AM, Christopher Graves <christoph.graves@gmail.com> wrote:


On Tue, Mar 27, 2012 at 3:31 AM, Mike Kaufman <mckauf@gmail.com> wrote:
On 3/26/12 12:49 PM, Christopher Graves wrote:
On Sun, Mar 11, 2012 at 2:32 PM, Christopher Graves
<christoph.graves@gmail.com <mailto:christoph.graves@gmail.com>> wrote:

       Try this:

       from pylab import *
       from matplotlib.ticker import AutoMinorLocator

       clf()
       ax=subplot(111)
       ax.autoscale(tight=True)
       plot([1,2,4],[1,2,3])
       ax.xaxis.set_minor_locator(__AutoMinorLocator(2))
       ax.yaxis.set_minor_locator(__AutoMinorLocator(2))

       draw()

       M

       PS: I believe this is a fairly new feature...


   Thanks! Great news that AutoMinorLocator has been added and
   accomplishes this. Regarding the P.S. I can confirm that the feature
   was not in matplotlib 1.0.1 - I had to update to 1.1.0 to use it.

   Best /Chris



Hi Mike,

A follow-up question... When using that, if one then tries to manually
use the zoom-box tool available with a matplotlib plot, if one draws too
small of a box (less than 2 major ticks in x or y dimension, based on
the following error message), it gives the following error and further
operations on the plot do not work.

ValueError: Need at least two major ticks to find minor tick locations
( File "/usr/lib/pymodules/python2.7/matplotlib/ticker.py", line 1528,
in __call__ )

Any way to avoid this for now? (And ultimately, should this be made into
a bug fix request?)


Ok, I seem to remember seeing this error before, but I can't trip it now (with either 1.1.1rc or today's git checkout of 1.2.x). Do you have
a short script that can reproduce this? For me, the zoom-box tool seems to be [correctly] setting the majortick locations as I zoom in, thus preventing this exception. I should note that I'm using the GTKAgg frontend. This may be the issue. A long time ago I was using the MacOSX frontend, and maybe this was when I was seeing it...

Aside from that, this would be a bug.

M

 
On Wed, Mar 28, 2012 at 10:50 PM, Christopher Graves <christoph.graves@gmail.com> wrote:
Hi Mike,

Ok I found the root cause. Here is a short script:


from pylab import *

from matplotlib.ticker import MultipleLocator, AutoMinorLocator

plot([0,3],[0,2.2])

ax = gca()

ax.xaxis.set_major_locator(MultipleLocator(0.5))

ax.xaxis.set_minor_locator(AutoMinorLocator(2))

show()


Once MultipleLocator has been called, the auto-reassigning of tick spacing when zooming (either with the zoom box or the cross and right-click drag) does not happen, and then AutoMinorLocator has the error because it has "majorstep = majorlocs[1] - majorlocs[0]" and majorlocs has less than 2 elements when zoomed in that far. (GTKAgg vs others doesn't matter.)

Seems like a bug. Is it the same in the newer mpl version you have?
For my purposes, a different fix could work, because my reason to use MultipleLocator is only to make x and y major ticks have equal spacing, as follows:

from pylab import *

from matplotlib.ticker import MultipleLocator, AutoMinorLocator

ax = subplot(111, aspect='equal')

plot([0,3],[0,1.1])

# Set the ticks to have the same interval on both x and y axes:

x_major_tick_interval = abs(ax.xaxis.get_ticklocs()[0]-ax.xaxis.get_ticklocs()[1])

ax.yaxis.set_major_locator(MultipleLocator(x_major_tick_interval))

# 2 minor ticks per major tick:

ax.yaxis.set_minor_locator(AutoMinorLocator(2))

ax.xaxis.set_minor_locator(AutoMinorLocator(2))

show()


aspect='equal' is not necessary to bring out the error, it just illustrates the purpose of this. Is there another way to fix the x and y tick interval as equal? (And ideally even maintain the equal spacing when zooming.. As it is, they initially show as equal, but when zooming they can lose equal visible spacing while maintaining equal value intervals.)


Best,

Chris



On Thu, Mar 29, 2012 at 4:06 AM, Mike Kaufman <mckauf@gmail.com> wrote:
I can confirm this bug on yesterday's checkout. About equal spacing, I don't know offhand. A question to ask the list I think. If you could, please file as an issue on the github tracker. Include your code nugget that reproduces. Thanks.

I don't have a lot of time at this moment, so hopefully somebody else looks at fixing it first.

M

 
Ok, bug is filed at https://github.com/matplotlib/matplotlib/issues/807
I did not realize that our last couple of messages were not sent to the mailing-list.

To others on mailing-list:
Apart from someone hopefully fixing this bug, does anyone know another way to fix the x and y tick interval as equal, besides the way I did it in the last code block above, which uses "ax.yaxis.set_major_locator(MultipleLocator(x_major_tick_interval))" after plotting?
(And ideally even maintain the equal spacing when zooming.. As it is, they initially show as equal, but when zooming they can lose equal visible spacing while maintaining equal value intervals.)

Best /Chris


Sorry for the long delay in responding.  I have a huge backlog of emails to get through.

It sounds like you want ax.set_aspect('equal') or something to that effect.  That will maintain it even after zooming.

Ben Root


No problem! I think I mis-communicated the issue. The example I put above already does have the aspect ratio 'equal', when preparing the plot: "ax = subplot(111, aspect='equal')"  The equal-aspect is maintained fine while zooming. What I also want is to have the x and y tick-spacing be equal and maintained. Making the tick spacing equal works fine in the way I did it in the example above, but when you zoom with either of the zoom-tools the tick-spacing is not maintained equal. (The example above can be run without the 2 lines near the end that have "AutoMinorLocator", to avoid the actual bug that occurs when zooming due to AutoMinorLocator.)

Best /Chris