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 Axes.relim when the first line is y_isdata=False and possible fix by mdboom · Pull Request #854 · matplotlib/matplotlib

Conversation

@mdboom

@mdboom mdboom commented May 28, 2013

Copy link
Copy Markdown
Member

You can reproduce the bug with:

from matplotlib import pyplot
ax = pyplot.axes()
ax.axvline(0.5)
ax.plot([-0.1, 0, 0.2, 0.1])
ax.relim()
ax.autoscale()
(ymin, ymax) = ax.get_ylim()
print ymin, ymax
pyplot.show()

Printed ylim is -0.2 1.0 where the upper bound should be something like 0.25. You will see that there is big space between data line and the top bound.

To workaround this problem, I defined the following functions:

def _update_line_limits(self, line, updatex=True, updatey=True):
    p = line.get_path()
    if p.vertices.size > 0:
        self.dataLim.update_from_path(p, self.ignore_existing_data_limits,
                                      updatex=updatex and line.x_isdata,
                                      updatey=updatey and line.y_isdata)
        if (updatex and line.x_isdata) or (updatey and line.y_isdata):
            self.ignore_existing_data_limits = False


def relim(self):
    self.dataLim.ignore(True)
    for (udatex, updatey) in [[True, False], [False, True]]:
        self.ignore_existing_data_limits = True
        for line in self.lines:
            _update_line_limits(self, line, udatex, updatey)

    for p in self.patches:
        self._update_patch_limits(p)

If you call relim(ax) instead of ax.relim(), printed ylim is -0.1 0.25. I just simply separate the update of the line limits for x and y axis. I think you can simply replace the two functions with Axes.relim and Ax._update_line_limits.

I have currently have no time for preparing executable development version of matplotlib and its test environment. I will send a pull request at some point when I am ready, but if somebody can "pull" the snippet above and test it, please do that.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ghost ghost assigned pelson Aug 19, 2012
@pelson

pelson commented Aug 19, 2012

Copy link
Copy Markdown
Member

This is still broken even with #731. Once that is in, I will take a closer look at this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pelson

pelson commented Sep 4, 2012

Copy link
Copy Markdown
Member

There is a deeper problem here. Notice how the following code results in different results:

>>> import matplotlib.pyplot as plt
>>> ax = plt.axes()
>>> plt.axvline(0.5)
>>> plt.plot([-0.1, 0, 0.2, 0.1])
>>> print ax.viewLim
Bbox('array([[ 0. , -0.2],\n       [ 3. ,  1. ]])')
>>> import matplotlib.pyplot as plt
>>> ax = plt.axes()
>>> plt.plot([-0.1, 0, 0.2, 0.1])
>>> plt.axvline(0.5)
>>> print ax.viewLim
Bbox('array([[ 0.  , -0.1 ],\n       [ 3.  ,  0.25]])')

Essentially, the problem comes down to the fact that the axes.ignore_existing_data_limits is not split into ignore x and ignore_y components. Unfortunately I don't think we can get a solution to this before the 1.2.x rc1, not least because it will need a change to some of the underlying cpp code in _path.cpp.

I should add, I don't think your ax.relim(); ax.autoscale() are strictly necessary. This should be what you get in the first place (at least, I can't get it to make any difference).

EDIT: Fixed attached code.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dmcdougall

dmcdougall commented Sep 4, 2012

Copy link
Copy Markdown
Member

@pelson I'm struggling to see the difference in those two pieces of code.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pelson

pelson commented Sep 4, 2012

Copy link
Copy Markdown
Member

Doh! I have edited it now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mdboom and others added 25 commits April 30, 2013 11:09
@mdboom
Cleanup formatting of setup messages
decbc33
@cimarronm
Fixes issue matplotlib#1960. Account for right/top spine data offset …
247689d
…on transform when doing spine.set_position(). Also includes a testcase for the data locations.
@mdboom
Bug if MPLCONFIGDIRS is set
50cbfd2
@cimarronm
Improved comment for data spine transform adjustment - taken from mdb…
c154674
…oom.
@Westacular @pelson
Switch agg backend to use pixfmt_rgba32_plain instead of pixfmt_rgba3…
c985196
…2, which fixes a problem with alpha-blending partially transparent backgrounds.
@efiring
Merge pull request matplotlib#1868 from pelson/alpha_background
89479d3
Fixed background colour of PNGs saved with a non-zero opacity.
@mdboom
Fix position of rotated text in Agg backend
db81ab2
@mdboom
Merge pull request matplotlib#1968 from mdboom/rotated_text
3120e6c
Rotated text element misalignment in Agg
pwuertz @pwuertz
figure: optionally configure automatic use of tight_layout
16d162b
@cimarronm
Added bullet to api_changes documentation on PR matplotlib#1964
6f45b43
@pwuertz
add test for automatic use of tight layout
8eb05dc
@mdboom
Merge pull request matplotlib#1929 from pelson/bbox_inches_contour_pr…
668690d
…oblem

Fixed failing bbox_inches='tight' case when a contour collection is empty
@Westacular
Fixes imsave so it does not flatten alpha-channel data (and updated t…
f16a1d3
…est to match)
@pelson @Westacular
Failing tests.
ae5c2f1
@Westacular
Fixes bug where linestyle always appears solid if linewidth is large …
1e7399f
…enough
@Westacular
Fixes bug where if alpha is set and edgecolor='none', edges would sti…
1aefc52
…ll be rendered as black.

Also fixes test case result that hit this bug
@Westacular
Changes backends to support of independent face and edge alphas
6cc8aaa
Specifically, alters the base, AGG, PDF, PGF, SVG, Cairo, and Mac OS X
backends to better enable the use of RGBA color values for both fills
and edges. An explicit alpha attribute, if set, will override the
alpha channels of the color values.

Updates test results, which are now what would be expected.

Also fixes a couple bugs with handling of linestyles.
@Westacular
Add additional patch tests.
a7f7cc7
@Westacular
Take Image object's alpha attribute into account when compositing mul…
2f10e68
…tiple images together.
@Westacular
Fix Cairo backend so Images are actually visible for output formats o…
547cb7b
…ther than PNG.
@Westacular
Add a test case for compositing images with an alpha attribute
04ee71e
@pelson
Merge pull request matplotlib#1956 from Westacular/imsave_alpha
b6b9062
Imsave now preserves the alpha channel.
@mdboom
Merge remote-tracking branch 'upstream/v1.2.x'
96ecc79
Conflicts:
	.travis.yml
	lib/matplotlib/tests/baseline_images/test_png/pngsuite.png
	lib/matplotlib/tests/test_axes.py
@Westacular
Added documentation of patch/alpha changes.
cd18645
@Westacular
Another documentation update
71e9ad9
mdboom added 5 commits May 28, 2013 11:45
@mdboom
Fix pdf_use14corefonts test
e5bd364
@mdboom
Fix tests
6588bb3
@mdboom
Merge pull request matplotlib#454 from mdboom/xdg_config
3ac8144
Use a subdirectory of $XDG_CONFIG_HOME instead of ~/.matplotlibrc on Linux
@mdboom
Merge pull request matplotlib#2050 from pelson/colormap_api
ebb7a9d
Added the from_levels_and_colors function.
@mdboom
Fix PEP8 whitespace issue
2af443e
@mdboom

mdboom commented May 28, 2013

Copy link
Copy Markdown
Member

I think the problem is deeper than @pelson suggests. _path.update_path_extents is already able to ignore an axis simply by putting the values out of order (i.e. (max, min) rather than (min, max)) for that axis. This works as designed (even if it's not the cleanest way to do things).

The problem here is that the "default" data range is (0, 1) on both axes. So when you start with a vline, it (correctly) ignores the y axis, and sets the xrange to (0.49, 0.51) and leaves the yrange as (0, 1). The subsequent auto limit operation on the line plot does not know that the previous y limits aren't meaningful, and therefore keeps them as they are (since they don't need to be expanded to show the data).

I think the fix here is to update relim and the Axes.__init__ constructor to start with the null data range rather than the unit data range. Then we know when a range isn't meaningful because it hasn't already been set to something finite.

I've attached a patch against 1.2.x (since this bug exists there, too), but I'm not entirely sure it isn't too big/risky for 1.2. I'd like to get this in for 1.3, however.

The attached PR also fixes #2061.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mdboom added 8 commits May 28, 2013 16:51
@mdboom
Update logo_sidebar_horiz.png
96ce689
@mdboom
Merge remote-tracking branch 'upstream/v1.2.x' into v1.3.x
0d2f9a7
@mdboom
Merge pull request matplotlib#2024 from mdboom/new_logo
493fa46
Update homepage image
@mdboom
Merge pull request matplotlib#2066 from GBillotey/oversized_doc_img
a92e00e
[DOC] Mathtext and matshow examples
@mdboom
Merge pull request matplotlib#2076 from cgohlke/patch-1
e2bf78e
Build the _windowing extension
@mdboom
Merge pull request matplotlib#2077 from rblomberg/yahoo-csv-url-fix
b13fc46
changed URL to the current CSV API for yahoo finance
@mdboom
Fix bug in XFG_CONFIG handling
b3bdf84
@mdboom
Fix deprecation warning when running tests
3b2f937
pelson
pelson reviewed May 29, 2013
View reviewed changes
Comment thread lib/matplotlib/transforms.py Outdated

@pelson pelson May 29, 2013

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see much point in defining this outside of the null staticmethod. Is there a performance reason?
Is there a reason for np.float_ rather than np.float or the more explicit np.float64?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mdboom mdboom May 29, 2013

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not -- just being symmetrical with unit.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@pelson

pelson commented May 29, 2013

Copy link
Copy Markdown
Member

I've attached a patch against 1.2.x (since this bug exists there, too), but I'm not entirely sure it isn't too big/risky for 1.2. I'd like to get this in for 1.3, however.

I don't think this can go into v1.2.x, the change is functional (admittedly it was unintentional behaviour in the first place).

The log scale test result is very different - its hard to know which one is expected, but it is without a doubt different behaviour. Would you mind providing your analysis on the test and why it was wrong?

Other than that, this is a nice solution - though I have to admit I'm not too fussed whether it makes it into the v1.3.x series or not.

Nice work @mdboom!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

pelson and others added 3 commits May 29, 2013 14:27
@pelson
Fixed failing test on python3.
b72b0f7
@mdboom
Merge pull request matplotlib#2080 from pelson/cmap_and_norm_levels_t…
e2d674c
…est_fix

Fixed failing test on python3.
@mdboom
Exclude the setuptools stubs in the correct way
8eef95e
@mdboom

mdboom commented May 29, 2013

Copy link
Copy Markdown
Member

The log scale test adds a axvline and axhline, both at a position 24.1. In the old version, the resulting limits were (0, 100), since the initial limits on a plot were (0, 1), and the ax?line call added to it. In the new version, the resulting limits are (10, 100), since it should only include the decades around the given value. I think this is the correct behavior.

Yeah -- I think I agree about not including this in 1.2.x. I'll rebase and create a new PR for 1.3.x, also incorporating your other comments.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pelson

pelson commented May 29, 2013

Copy link
Copy Markdown
Member

Yeah -- I think I agree about not including this in 1.2.x. I'll rebase and create a new PR for 1.3.x, also incorporating your other comments.

Great. And thanks for the explanation - I'm more comfortable with the change now. The only remaining work is to add an API change entry for the change.

Cheers,

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mdboom added 4 commits May 29, 2013 11:09
@mdboom
Wait until font caches exist before starting tests
33faad1
@mdboom
Correctly set the initial data limit bounding box to null limits rath…
18d25f9
…er than the unit bounding box.
@mdboom
Only do the strange autoscale on/off thing when doing a histogram bar…
a129662
… plot
@mdboom
Simplify handling of unit and null bboxes
412f1b3
@mdboom mdboom mentioned this pull request May 29, 2013
Data limits (on 1.3.x) #2082
Merged
@mdboom

mdboom commented May 29, 2013

Copy link
Copy Markdown
Member

Closing in favor of #2082.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mdboom mdboom closed this May 29, 2013
@mdboom
mdboom deleted the data_limits branch August 7, 2014 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@mdboom mdboom

Labels

status: confirmed bug

Projects

None yet

Milestone

v1.3.x blocker

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

19 participants

@mdboom @pelson @dmcdougall @efiring @leejjoon @megies @cimarronm @Westacular @pwuertz @tonysyu @GBillotey @neggert @adrn @phobson @drevicko @tacaswell @bfroehle @takluyver @ivanov
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — 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.