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

Skip to content

hline at y=0 appears after setting yscale to log #8783

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
dstansby opened this issue Jun 20, 2017 · 4 comments
Closed

hline at y=0 appears after setting yscale to log #8783

dstansby opened this issue Jun 20, 2017 · 4 comments
Milestone

Comments

@dstansby
Copy link
Member

Bug report

Bug summary

Calling ax.axhline(0) after setting the y-scale to log rescales the y-axis to make the horizontal line appear at 1e-300.

Code for reproduction

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.scatter([1], [1])
ax.set_yscale('log')
ax.axhline(0)
plt.show()

Actual outcome

figure_1
with the warning

/Users/dstansby/matplotlib/lib/matplotlib/axes/_base.py:3208: UserWarning: Attempted to set non-positive ylimits for log-scale axis; invalid limits will be ignored.
  'Attempted to set non-positive ylimits for log-scale axis; '

Expected outcome
I would expect the horizontal line to be ignored, and axis limits to remain as they were originally.

Matplotlib version

  • Operating System: OSX 10.12.5
  • Matplotlib Version: master branch installed using pip
  • Python Version: 3.6.1
@dstansby dstansby changed the title vline at y=0 appears after setting yscale to log hline at y=0 appears after setting yscale to log Jun 20, 2017
@tacaswell tacaswell added this to the 2.1 (next point release) milestone Jun 20, 2017
@tacaswell
Copy link
Member

On the other hand, you asked it to draw a line at 0 a it made a best-effort to do so. What does a line at a negative position do?

@anntzer
Copy link
Contributor

anntzer commented Jun 20, 2017

Do nothing, which is what happens when the call to scatter is not included.
OTOH this is fixed by #8537.

@dstansby
Copy link
Member Author

Trying a line at a negative position (ax.axhline(-1)) results in exactly the same behavior as above.

Changing the code to

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.scatter([1], [1])
plt.semilogy()
ax.axhline(0)
plt.show()

ignores the hline completely, and just shows the single scatter point as it was before. In my opinion I think this should be the behavior of `ax.set_yscale('log') too. At the very least they should be consistent which I think is what #8537 is for.

@dstansby
Copy link
Member Author

Fixed by #8836

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants