Skip to content

[MRG+1] plot_date() after axhline() doesn't rescale axes #8205

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
wants to merge 12 commits into from
22 changes: 18 additions & 4 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4973,24 +4973,26 @@ def test_bar_single_height():
# Check that a horizontal chart with one width works
ax.bar(0, 1, bottom=range(4), width=1, orientation='horizontal')


def test_datetime_axhline_same_axes():
Copy link
Member

Choose a reason for hiding this comment

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

The pep8 checker is probably going to want 2 blank lines between functions

Copy link
Member

Choose a reason for hiding this comment

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

Looks like you'll also need to trim trailing whitespace:
https://travis-ci.org/matplotlib/matplotlib/jobs/208246492#L1683

# This test was suggested by Paul Hobson (@phobson) regarding issue 7742
# Check when ploting datetime data and horizontal line
# Check when ploting datetime data and horizontal line
# order of plotting doesn't matter.
# axhline() should not change x axis limits.
from datetime import datetime
fig, axs = plt.subplots(2, 1)
xvalues = [datetime(2016, 1, 1, 0, 0, 0), datetime(2016, 1, 2, 0, 0, 0)]
yvalues = [1, 2]

axs[0].plot(xvalues, yvalues)
axs[0].axhline(1.5)

axs[1].axhline(1.5)
axs[1].plot(xvalues, yvalues)

assert (axs[0].get_xlim() == axs[1].get_xlim())


def test_datetime_axvline_same_axes():
# This is similar to test above
from datetime import datetime
Expand All @@ -5005,3 +5007,15 @@ def test_datetime_axvline_same_axes():
axs[1].plot(xvalues, yvalues)

assert (axs[0].get_ylim() == axs[1].get_ylim())


def test_invalid_axis_limits():
plt.plot([0, 1], [0, 1])
with pytest.raises(ValueError):
plt.xlim(np.nan)
with pytest.raises(ValueError):
plt.xlim(np.inf)
with pytest.raises(ValueError):
plt.ylim(np.nan)
with pytest.raises(ValueError):
plt.ylim(np.inf)