Re: [Matplotlib-users] how to maintain fractional minor tick spacing From: Michael Droettboom - 2012-06-22 12:55 ```> On Thu, Jun 21, 2012 at 12:54 AM, Christopher Graves > > wrote: > > > Has anyone had a chance to take a look at this very annoying bug > with using AutoMinorLocator? > > > > Ok, I proposed a simple bug fix at > https://github.com/matplotlib/matplotlib/issues/807 > How does one go about submitting this to the matplotlib package? Submitting to a github issue (as you've done) certainly works, and one of the developers should get to it soon. We don't require it, but the next level of contribution would be to submit pull requests. This is described in the matplotlib developer docs here: http://matplotlib.sourceforge.net/devel/gitwash/index.html But if you're not a regular git user and that's too much overhead for a simple patch, I wouldn't worry about it. Mike ```

[Matplotlib-users] how to maintain fractional minor tick spacing cgraves <christoph.graves@gm...>
 Re: [Matplotlib-users] how to maintain fractional minor tick spacing From: Mike Kaufman - 2012-03-11 13:06 ```On 3/11/12 8:14 AM, cgraves wrote: > > Hi, here is an example script which places minor ticks with 2 per major tick > (minor tick spacing is "fractional" of major tick spacing with relative > interval of 1/2): > > from pylab import * > fig=figure() > ax=subplot(111) > ax.autoscale(tight=True) > plot([1,2,4],[1,2,3]) > x_ticks_maj_spacing = > float(abs(ax.xaxis.get_ticklocs()[0]-ax.xaxis.get_ticklocs()[1])) > x_ticks_min_spacing = x_ticks_maj_spacing/2 > ax.xaxis.set_minor_locator(MultipleLocator(x_ticks_min_spacing)) > y_ticks_maj_spacing = > float(abs(ax.yaxis.get_ticklocs()[0]-ax.yaxis.get_ticklocs()[1])) > y_ticks_min_spacing = y_ticks_maj_spacing/2 > ax.yaxis.set_minor_locator(MultipleLocator(y_ticks_min_spacing)) > show() > > This works fine. However, if one changes the axes limits then the major > ticks get automatically adjusted to a different interval but the minor ticks > remain at the positions they were already at. To see this, either use the > zoom tools or do the following after running the above: > > xlim(1,2.5) > fig.canvas.draw() > > The question is, what is the best way to maintain the fractional minor tick > spacing? I suppose one could set up a way to update the set_minor_locator > and redraw the figure each time the figure axes limits are adjusted, but is > there a better way? 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... ```

 Re: [Matplotlib-users] how to maintain fractional minor tick spacing From: Christopher Graves - 2012-03-11 13:33 Attachments: Message as HTML ```On Sun, Mar 11, 2012 at 2:06 PM, Mike Kaufman wrote: > On 3/11/12 8:14 AM, cgraves wrote: > >> >> Hi, here is an example script which places minor ticks with 2 per major >> tick >> (minor tick spacing is "fractional" of major tick spacing with relative >> interval of 1/2): >> >> from pylab import * >> fig=figure() >> ax=subplot(111) >> ax.autoscale(tight=True) >> plot([1,2,4],[1,2,3]) >> x_ticks_maj_spacing = >> float(abs(ax.xaxis.get_**ticklocs()[0]-ax.xaxis.get_**ticklocs()[1])) >> x_ticks_min_spacing = x_ticks_maj_spacing/2 >> ax.xaxis.set_minor_locator(**MultipleLocator(x_ticks_min_**spacing)) >> y_ticks_maj_spacing = >> float(abs(ax.yaxis.get_**ticklocs()[0]-ax.yaxis.get_**ticklocs()[1])) >> y_ticks_min_spacing = y_ticks_maj_spacing/2 >> ax.yaxis.set_minor_locator(**MultipleLocator(y_ticks_min_**spacing)) >> show() >> >> This works fine. However, if one changes the axes limits then the major >> ticks get automatically adjusted to a different interval but the minor >> ticks >> remain at the positions they were already at. To see this, either use the >> zoom tools or do the following after running the above: >> >> xlim(1,2.5) >> fig.canvas.draw() >> >> The question is, what is the best way to maintain the fractional minor >> tick >> spacing? I suppose one could set up a way to update the set_minor_locator >> and redraw the figure each time the figure axes limits are adjusted, but >> is >> there a better way? >> > > 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 ```

 Re: [Matplotlib-users] how to maintain fractional minor tick spacing From: Christopher Graves - 2012-03-26 16:49 Attachments: Message as HTML ```On Sun, Mar 11, 2012 at 2:32 PM, Christopher Graves < christoph.graves@...> wrote: > On Sun, Mar 11, 2012 at 2:06 PM, Mike Kaufman wrote: > >> On 3/11/12 8:14 AM, cgraves wrote: >> >>> >>> Hi, here is an example script which places minor ticks with 2 per major >>> tick >>> (minor tick spacing is "fractional" of major tick spacing with relative >>> interval of 1/2): >>> >>> from pylab import * >>> fig=figure() >>> ax=subplot(111) >>> ax.autoscale(tight=True) >>> plot([1,2,4],[1,2,3]) >>> x_ticks_maj_spacing = >>> float(abs(ax.xaxis.get_**ticklocs()[0]-ax.xaxis.get_**ticklocs()[1])) >>> x_ticks_min_spacing = x_ticks_maj_spacing/2 >>> ax.xaxis.set_minor_locator(**MultipleLocator(x_ticks_min_**spacing)) >>> y_ticks_maj_spacing = >>> float(abs(ax.yaxis.get_**ticklocs()[0]-ax.yaxis.get_**ticklocs()[1])) >>> y_ticks_min_spacing = y_ticks_maj_spacing/2 >>> ax.yaxis.set_minor_locator(**MultipleLocator(y_ticks_min_**spacing)) >>> show() >>> >>> This works fine. However, if one changes the axes limits then the major >>> ticks get automatically adjusted to a different interval but the minor >>> ticks >>> remain at the positions they were already at. To see this, either use the >>> zoom tools or do the following after running the above: >>> >>> xlim(1,2.5) >>> fig.canvas.draw() >>> >>> The question is, what is the best way to maintain the fractional minor >>> tick >>> spacing? I suppose one could set up a way to update the set_minor_locator >>> and redraw the figure each time the figure axes limits are adjusted, but >>> is >>> there a better way? >>> >> >> 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?) Best /Chris ```

 Re: [Matplotlib-users] how to maintain fractional minor tick spacing From: Mike Kaufman - 2012-03-27 01:31 ```On 3/26/12 12:49 PM, Christopher Graves wrote: > On Sun, Mar 11, 2012 at 2:32 PM, Christopher Graves > > 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 ```

 Re: [Matplotlib-users] how to maintain fractional minor tick spacing From: Christopher Graves - 2012-03-29 09:53 Attachments: Message as HTML ```On Tue, Mar 27, 2012 at 3:31 AM, Mike Kaufman wrote: > On 3/26/12 12:49 PM, Christopher Graves wrote: > >> On Sun, Mar 11, 2012 at 2:32 PM, Christopher Graves >> > 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@...> 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 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 ```

 Re: [Matplotlib-users] how to maintain fractional minor tick spacing From: Benjamin Root - 2012-04-12 15:21 Attachments: Message as HTML ```On Thu, Mar 29, 2012 at 5:53 AM, Christopher Graves < christoph.graves@...> wrote: > > > On Tue, Mar 27, 2012 at 3:31 AM, Mike Kaufman wrote: > >> On 3/26/12 12:49 PM, Christopher Graves wrote: >> >>> On Sun, Mar 11, 2012 at 2:32 PM, Christopher Graves >>> > 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@...> 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 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 ```

 Re: [Matplotlib-users] how to maintain fractional minor tick spacing From: Christopher Graves - 2012-04-12 18:30 Attachments: Message as HTML ```On Thu, Apr 12, 2012 at 5:20 PM, Benjamin Root wrote: > > > On Thu, Mar 29, 2012 at 5:53 AM, Christopher Graves < > christoph.graves@...> wrote: > >> >> >> On Tue, Mar 27, 2012 at 3:31 AM, Mike Kaufman wrote: >> >>> On 3/26/12 12:49 PM, Christopher Graves wrote: >>> >>>> On Sun, Mar 11, 2012 at 2:32 PM, Christopher Graves >>>> > 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@...> 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 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 ```

 Re: [Matplotlib-users] how to maintain fractional minor tick spacing From: Christopher Graves - 2012-06-20 22:55 Attachments: Message as HTML ```On Tue, Mar 27, 2012 at 3:31 AM, Mike Kaufman wrote: > On 3/26/12 12:49 PM, Christopher Graves wrote: > >> On Sun, Mar 11, 2012 at 2:32 PM, Christopher Graves >> > 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@...> 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 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 > On Thu, Mar 29, 2012 at 11:53 AM, Christopher Graves < christoph.graves@...> wrote: > > Ok, bug is filed at https://github.com/matplotlib/matplotlib/issues/807 > Has anyone had a chance to take a look at this very annoying bug with using AutoMinorLocator? Best, Chris ```

 Re: [Matplotlib-users] how to maintain fractional minor tick spacing From: Christopher Graves - 2012-06-21 21:56 Attachments: Message as HTML ```On Tue, Mar 27, 2012 at 3:31 AM, Mike Kaufman wrote: > On 3/26/12 12:49 PM, Christopher Graves wrote: > >> On Sun, Mar 11, 2012 at 2:32 PM, Christopher Graves >> > 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@...> 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 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 > On Thu, Mar 29, 2012 at 11:53 AM, Christopher Graves < christoph.graves@...> wrote: > > Ok, bug is filed at https://github.com/matplotlib/matplotlib/issues/807 > On Thu, Jun 21, 2012 at 12:54 AM, Christopher Graves < christoph.graves@...> wrote: > > Has anyone had a chance to take a look at this very annoying bug with > using AutoMinorLocator? > Ok, I proposed a simple bug fix at https://github.com/matplotlib/matplotlib/issues/807 How does one go about submitting this to the matplotlib package? Best, Chris ```

 Re: [Matplotlib-users] how to maintain fractional minor tick spacing From: Michael Droettboom - 2012-06-22 12:55 Attachments: Message as HTML ```> On Thu, Jun 21, 2012 at 12:54 AM, Christopher Graves > > wrote: > > > Has anyone had a chance to take a look at this very annoying bug > with using AutoMinorLocator? > > > > Ok, I proposed a simple bug fix at > https://github.com/matplotlib/matplotlib/issues/807 > How does one go about submitting this to the matplotlib package? Submitting to a github issue (as you've done) certainly works, and one of the developers should get to it soon. We don't require it, but the next level of contribution would be to submit pull requests. This is described in the matplotlib developer docs here: http://matplotlib.sourceforge.net/devel/gitwash/index.html But if you're not a regular git user and that's too much overhead for a simple patch, I wouldn't worry about it. Mike ```

 Re: [Matplotlib-users] how to maintain fractional minor tick spacing From: Benjamin Root - 2012-06-22 13:28 Attachments: Message as HTML ```On Fri, Jun 22, 2012 at 8:55 AM, Michael Droettboom wrote: > > On Thu, Jun 21, 2012 at 12:54 AM, Christopher Graves < > christoph.graves@...> wrote: > >> >> Has anyone had a chance to take a look at this very annoying bug with >> using AutoMinorLocator? >> > > > Ok, I proposed a simple bug fix at > https://github.com/matplotlib/matplotlib/issues/807 > How does one go about submitting this to the matplotlib package? > > Submitting to a github issue (as you've done) certainly works, and one of > the developers should get to it soon. > > We don't require it, but the next level of contribution would be to submit > pull requests. This is described in the matplotlib developer docs here: > > http://matplotlib.sourceforge.net/devel/gitwash/index.html > > But if you're not a regular git user and that's too much overhead for a > simple patch, I wouldn't worry about it. > > Mike > > I submitted this PR: https://github.com/matplotlib/matplotlib/issues/807 The suggestion isn't a full solution, as I would rather see that the minor ticks still gets drawn, but at least it doesn't crash anymore. Of course, I am not entirely certain of the value of having the minor ticks disappear and so this would just introduce "buggy" behavior, in a sense. Ben Root ```