Thanks to visit codestin.com
Credit goes to github.com

Skip to content

plt.bar() creates different results when repeated #13909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tlkaufmann opened this issue Apr 9, 2019 · 9 comments
Closed

plt.bar() creates different results when repeated #13909

tlkaufmann opened this issue Apr 9, 2019 · 9 comments
Labels
status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. status: inactive Marked by the “Stale” Github Action

Comments

@tlkaufmann
Copy link

Bug report

Bug summary

When plotting a bar graph of some data from np.histogram on several different axis the outcome always slightly differs from each other.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

data = np.random.uniform(0, 100, size = 100)
hist, bins = np.histogram(data, bins=100)

fig, ax = plt.subplots(ncols = 3)

for a in ax:
    a.bar(bins[:-1], hist)

Actual outcome
pyplot_bar

Expected outcome

The same barplot three times.

Matplotlib version

  • Operating system: Ubuntu 18.04
  • Matplotlib version: 3.0.2
  • Matplotlib backend (print(matplotlib.get_backend())): module://ipykernel.pylab.backend_inline
  • Python version: 3.7.1
  • Jupyter version (if applicable): IPython 7.2.0

Matplotlib installed via standard conda channel.

@MrMonk3y
Copy link

MrMonk3y commented Apr 9, 2019

same issue

@goyodiaz
Copy link

goyodiaz commented Apr 9, 2019

It is a rendering issue that you can aminorate by making the figure or the bars wider. There is a limit to what can be done when you have more bars than horizontal pixels and the bars are less than 1 pixel wide.

@MrMonk3y
Copy link

MrMonk3y commented Apr 9, 2019

It is a rendering issue that you can aminorate by making the figure or the bars wider. There is a limit to what can be done when you have more bars than horizontal pixels and the bars are less than 1 pixel wide.

But then it would still be better to plot three times the same aliased plot, wouldn't it?

@ImportanceOfBeingErnest
Copy link
Member

The problem is that the axes position is in fractional units of the figure. Hence the same plot at different positions inside the figure will have different pixels being ommitted.

In general if you have bars of width smaller than a pixel, consider

  • not using bars at all, possibly step might be better suited, or
  • make sure to plot the bar edges, e.g. a.bar(bins[:-1], hist, edgecolor="C0", linewidth=0.72) in this case.

@ImportanceOfBeingErnest ImportanceOfBeingErnest added the Community support Users in need of help. label Apr 9, 2019
@tlkaufmann
Copy link
Author

Thanks for the explanation!

@jklymak jklymak reopened this Apr 9, 2019
@jklymak
Copy link
Member

jklymak commented Apr 9, 2019

Re-opening. I think there should be the option to properly anti-alias here ala #13724. However, this canvas-level anti-aliasing will have to happen at a lower level...

@MrMonk3y
Copy link

MrMonk3y commented Apr 9, 2019

There should at least be one of those red warnings when the image is smaller than the resolution needed to plot the bars correclty.

@dstansby dstansby removed the Community support Users in need of help. label Sep 4, 2019
@anntzer
Copy link
Contributor

anntzer commented Sep 4, 2019

I guess this is basically the same issue as the one being discussed at #13236 (comment)?

@github-actions
Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Jun 12, 2023
@github-actions github-actions bot added the status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. label Jul 12, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. status: inactive Marked by the “Stale” Github Action
Projects
None yet
Development

No branches or pull requests

7 participants