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 — fill_between incorrect with log y-axis and value 0 · Issue #8623 · matplotlib/matplotlib

fill_between incorrect with log y-axis and value 0 #8623

New issue
Copy link
New issue
Copy link
Closed
Closed
fill_between incorrect with log y-axis and value 0#8623
Copy link
Labels
status: confirmed bug
Milestone
v2.1.1

Description

@cdeil
cdeil
opened on May 15, 2017
Issue body actions

fill_between doesn't give the result I expect if using a log y-axis and having a value of 0 in the y1 array.

Example:

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt

x = np.array([1, 2, 3, 4, 5])
y1 = np.array([9, 2, 8, 3, 0])
y2 = np.array([10, 10, 10, 10, 10])

plt.plot(x, y1, lw=3, color='green')
plt.plot(x, y2, lw=3, color='red')
plt.fill_between(x, y1, y2)
plt.loglog()

Actual outcome:

The polygon created by fill_between somehow connects the last and first point, resulting in a completely incorrect patch:

image

Expected outcome

I was expecting / hoping that the band would be filled correctly and simply clipped (i.e. the result I get when changing the last y1 value from 0 to e.g. 1e-10). In the plot, the blue fill should be between the red and green line.

Matplotlib version

This is with Matplotlib 2.0.0.
(on Macports, but I don't think that matters)

Activity

  1. dstansby
    added
    status: confirmed bug
    on May 15, 2017
  2. dstansby
    added this to the This milestone has been deleted milestone on May 15, 2017
  3. dstansby commented on May 15, 2017

    @dstansby
    dstansby
    on May 15, 2017
    Member
    More actions

    Confirmed on master, thanks for the code sample.

  4. dstansby commented on May 15, 2017

    @dstansby
    dstansby
    on May 15, 2017
    Member
    More actions

    Slightly abstractly, y=0 is mapped to x = -infinity on a log scale, so I would expect the fill between to be clipped at the vertical line x=4 in the above example, and for the x=5, y=0 point to be ignored.

  5. cdeil commented on May 15, 2017

    @cdeil
    cdeil
    on May 15, 2017
    ContributorAuthor
    More actions

    @dstansby - Thanks for looking into the issue!

    When creating the issue I forgot to mention #7371 .
    I don't quite follow the discussion there, but it might be relevant to decide what to do here.
    For me, any solution that doesn't have this issue that the last y1 point connects to the first y2 point would be fine.

    Also, if someone else has this issue, I wanted to mention that it's possible to work around the issue using where and filtering out the non-positive y values:

    where = (y_hi > 0) & (y_lo > 0) & (other possible selections you might have)
    ax.fill_between(energy.value, y_lo.value, y_hi.value, where=where)

    This is what I'm doing for now.

  6. cdeil commented on Jul 3, 2017

    @cdeil
    cdeil
    on Jul 3, 2017
    ContributorAuthor
    More actions

    @Tuan333 - Yes, indeed nonposy='clip' resolves the issue, thanks for pointing it out.

    The main remaining issue is that we have to teach our users about it, because if they call plt.loglog without that option after calling the plotting functions from our package, they will still see that issue.

    Close this issue?
    Or is there anything that can be improved on the matplotlib side (e.g. change default behaviour)?

  7. anntzer commented on Jul 3, 2017

    @anntzer
    anntzer
    on Jul 3, 2017
    Contributor
    More actions

    Probably related to #8537?

  8. dstansby commented on Jul 3, 2017

    @dstansby
    dstansby
    on Jul 3, 2017 via email
    Member
    More actions
    Yeah, I think finishing that PR will fix this and a few other open bugs. I'll try and get round to it in the next couple of days.
    …
    On 3 Jul 2017 8:03 pm, "Antony Lee" ***@***.***> wrote: Probably related to #8537 <#8537>? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#8623 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AF6RfHrvIf6rvOy78OZB_MIIuUqwaXunks5sKTsIgaJpZM4NbNpa> .
  9. tacaswell commented on Jul 5, 2017

    @tacaswell
    tacaswell
    on Jul 5, 2017
    Member
    More actions

    @dstansby Won't #8836 make this worse (by changing more things to mask rather than clip)?

  10. dstansby commented on Jul 6, 2017

    @dstansby
    dstansby
    on Jul 6, 2017
    Member
    More actions

    I don't think it'll make it worse than the image in the original bug report, but it certainly doesn't fix it.

  11. tacaswell
    modified the milestones: This milestone has been deleted, This milestone has been deleted on Sep 24, 2017
  12. afvincent commented on Nov 1, 2017

    @afvincent
    afvincent
    on Nov 1, 2017
    Contributor
    More actions

    Currently, the MWE results in
    mwe_with_master
    with Matplotlib from master (2.1.0.post476+g30b58001f). (The issue is still present with Matplotlib 2.1 from conda)

    @tacaswell @anntzer
    Should we close this issue (didn't #9477 fixed it?)?

  13. tacaswell commented on Nov 1, 2017

    @tacaswell
    tacaswell
    on Nov 1, 2017
    Member
    More actions

    I think this is fixed by #9477

  14. tacaswell
    closed this as completedon Nov 1, 2017
  15. tacaswell
    modified the milestones: This milestone has been deleted, v2.1.1 on Nov 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: confirmed bug

    Type

    No type

    Projects

    No projects

      Milestone

      • v2.1.1

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.