FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Bug in set_view_interval · Issue #118 · matplotlib/matplotlib · GitHub

Repository navigation

Bug in set_view_interval #118

Closed
Closed

Description

The following code should produce an image that is 3600x3216 and completely blue, but there is a 1-pixel white border on the bottom and left:

import numpy as np

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as mpl

fig = mpl.figure(figsize=(12.00, 12.00 * 3216. / 3600.))
ax = fig.add_axes([0.,0.,1.,1.])

ax.set_autoscale_on(False)

ax.xaxis.set_view_interval(0.5, 3600.5)
ax.yaxis.set_view_interval(0.5, 3216.5)

for tick in ax.xaxis.get_ticklines():
    tick.set_visible(False)

for tick in ax.yaxis.get_ticklines():
    tick.set_visible(False)

for label in ax.xaxis.get_ticklabels():
    label.set_visible(False)

for label in ax.yaxis.get_ticklabels():
    label.set_visible(False)

for key in ax.spines:
    ax.spines[key].set_visible(False)

ax.imshow(np.zeros((3216, 3600)), extent=(0.5, 3600.5, 0.5, 3216.5), origin='lower')
fig.savefig('test.png', dpi=300, transparent=False)

If autoscale is turned on, it looks fine, but I need to keep autoscale off for other reasons, so I want to understand what's going on here. If I do:

print ax.xaxis.get_view_interval()
print ax.yaxis.get_view_interval()

I get:

[    0.   3600.5]
[    0.   3216.5]

which must be part of the issue here, since the minima should be 0.5, not 0. If I use set_xlim and set_ylim instead of ax.xaxis.set_view_interval, it works fine, so there must be a bug in set_view_interval?

Note that this issue is not related to #117, and occurs even if the patch in #117 is applied.

Activity

  1. astrofrog commented on May 21, 2011

    ContributorAuthor

    In def set_view_interval in axis.py, should the following lines:

            Vmin, Vmax = self.get_view_interval()
            if Vmin < Vmax:
                self.axes.viewLim.intervalx = (min(vmin, vmax, Vmin),
                                               max(vmin, vmax, Vmax))
            else:
                self.axes.viewLim.intervalx = (max(vmin, vmax, Vmin),
                                               min(vmin, vmax, Vmax))
    

    Not be the following?

            if Vmin < Vmax:
                self.axes.viewLim.intervalx = (min(vmin, vmax),
                                               max(vmin, vmax))
            else:
                self.axes.viewLim.intervalx = (max(vmin, vmax),
                                               min(vmin, vmax))
    

    Basically, the old limits should be used to determine the order, but apart from that, why should they appear in the min(...) and max(...) expressions?

  2. leejjoon commented on May 24, 2011

    Contributor

    The changelog entry of the associated commit seems to indicate that this is an intended behavior.

    cb5cab4

    @efiring, can you comment on this?

    For example,

     ax = plt.subplot(111)
    
     ax.xaxis.set_view_interval(5, 10, ignore=False)
     print ax.xaxis.get_view_interval()
    
     ax.xaxis.set_view_interval(5, 10, ignore=True)
     print ax.xaxis.get_view_interval()

    prints

    [  0.  10.]
    [  5.  10.]

    which seems a bit inconsistent.

  3. efiring commented on May 24, 2011

    Member

    On 05/23/2011 06:57 PM, leejjoon wrote:

    The changelog entry of the associated commit seems to indicate that this is an intended behavior.

    cb5cab4

    @efiring, can you comment on this?

    The problem here is that Axis.set_view_interval should be an obscure
    private method, or it should be broken up into two methods, perhaps one
    or both of which should also be obscure and private; its only internal
    use, as far as I can see, is in ticker.py. The methods that are
    intended for public use in setting the viewLim are the Axes methods.
    The original implementation of Axis.set_view_interval was broken for its
    original purpose; I fixed that, but did not put enough additional
    explanation in the docstring (which was previously missing entirely, and
    maybe should have been left so) to fully explain what the ignore kwarg
    does--which is to change the behavior so that it not only preserves the
    original order (hence axis inversion, if any), but also permits only
    expansion, not contraction, of the interval. It is this very different
    sort of functionality, required by ticker, that is causing the confusion.

    So: minimal solution is to improve the docstring; a cleaner long-term
    solution would involve ending up with two methods instead of one, and no
    kwarg. How to do this in with minimal user code breakage and with good,
    readable names for all methods is not obvious to me yet.

    Eric

    For example,

      ax = plt.subplot(111)
    
      ax.xaxis.set_view_interval(5, 10, ignore=False)
      print ax.xaxis.get_view_interval()
    
      ax.xaxis.set_view_interval(5, 10, ignore=True)
      print ax.xaxis.get_view_interval()

    prints

    [  0.  10.]
    [  5.  10.]

    which seems a bit inconsistent.

  4. astrofrog commented on May 24, 2011

    ContributorAuthor

    Ok, I understand now that these methods are not meant to be public. I'm not sure why I originally used them instead of set_xlim and set_ylim, but I must have stumbled upon them and assumed they were public. I'm just going to switch to set_xlim and set_ylim for my code.

  5. ghost assigned on Jun 15, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL