GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Bug in set_view_interval · Issue #118 · matplotlib/matplotlib

Bug in set_view_interval #118

New issue
Copy link
New issue
Copy link
Closed
Closed
Bug in set_view_interval#118
Copy link
Assignees
efiring
Milestone
v1.0.x

Description

@astrofrog
astrofrog
opened on May 17, 2011
Issue body actions

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

    @astrofrog
    astrofrog
    on May 21, 2011
    ContributorAuthor
    More actions

    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

    @leejjoon
    leejjoon
    on May 24, 2011
    Contributor
    More actions

    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

    @efiring
    efiring
    on May 24, 2011
    Member
    More actions

    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

    @astrofrog
    astrofrog
    on May 24, 2011
    ContributorAuthor
    More actions

    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
    efiring
    on Jun 15, 2011
  6. efiring
    added a commit that references this issue on Aug 20, 2011

    axis.py: clarify docstring for set_view_interval. Closes issue #118.

    a96422e
  7. efiring
    closed this as completedon Aug 20, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @efiring
    efiring

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    • v1.0.x

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.