-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: xticks unnecessarily rotated #34334
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
Changes from 18 commits
4282445
06e283f
2249626
aa8bd31
09f93bd
9c26c59
cdb6ce2
ea92292
d87f25f
3fc9930
85638c0
76c3b8d
7e01df8
2ea78de
2358716
eacbe0a
836dd0d
ea525ec
85c4dc8
645905d
c0c0e99
fbff1bd
c897d57
bb5b080
9bc93da
69a4c36
b093d68
5746bd6
29de029
cc9aebf
ee4d9bd
7ef0382
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
from pandas._libs.tslibs import to_offset | ||
import pandas.util._test_decorators as td | ||
|
||
from pandas import DataFrame, Index, NaT, Series, isna | ||
from pandas import DataFrame, Index, NaT, Series, isna, to_datetime | ||
import pandas._testing as tm | ||
from pandas.core.indexes.datetimes import bdate_range, date_range | ||
from pandas.core.indexes.period import Period, PeriodIndex, period_range | ||
|
@@ -1491,6 +1491,34 @@ def test_matplotlib_scatter_datetime64(self): | |
expected = "2017-12-12" | ||
assert label.get_text() == expected | ||
|
||
def test_check_xticks_rot(self): | ||
# https://github.com/pandas-dev/pandas/issues/29460 | ||
# irregular time series | ||
x = to_datetime(["2020-05-01", "2020-05-02", "2020-05-04"]) | ||
df = DataFrame({"x": x, "y": [1, 2, 3]}) | ||
axes = df.plot(x="x", y="y") | ||
self._check_ticks_props(axes, xrot=30) | ||
|
||
# use timeseries index | ||
axes = df.set_index("x").plot(y="y", use_index=True) | ||
self._check_ticks_props(axes, xrot=30) | ||
|
||
# separate subplots | ||
axes = df.plot(x="x", y="y", subplots=True, sharex=True) | ||
self._check_ticks_props(axes, xrot=30) | ||
axes = df.plot(x="x", y="y", subplots=True, sharex=False) | ||
self._check_ticks_props(axes, xrot=0) | ||
|
||
# index of dates but don't use index | ||
axes = df.set_index("x").plot(y="y", use_index=False) | ||
self._check_ticks_props(axes, xrot=0) | ||
|
||
# regular time series | ||
x = to_datetime(["2020-05-01", "2020-05-02", "2020-05-03"]) | ||
df = DataFrame({"x": x, "y": [1, 2, 3]}) | ||
axes = df.plot(x="x", y="y") | ||
self._check_ticks_props(axes, xrot=0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not a big issue, i would prefer to shuffle the tests a bit to put similar tests together because it's quite clear there are three sub-groups to test, I would prefer something like this: # regular time series
x = to_datetime(["2020-05-01", "2020-05-02", "2020-05-03"])
df = DataFrame({"x": x, "y": [1, 2, 3]})
axes = df.plot(x="x", y="y")
self._check_ticks_props(axes, xrot=0)
# irregular time series
x = to_datetime(["2020-05-01", "2020-05-02", "2020-05-04"])
df = DataFrame({"x": x, "y": [1, 2, 3]})
axes = df.plot(x="x", y="y")
self._check_ticks_props(axes, xrot=30)
# use timeseries index or not
axes = df.set_index("x").plot(y="y", use_index=True)
self._check_ticks_props(axes, xrot=30)
axes = df.set_index("x").plot(y="y", use_index=False)
self._check_ticks_props(axes, xrot=0)
# separate subplots
axes = df.plot(x="x", y="y", subplots=True, sharex=True)
self._check_ticks_props(axes, xrot=30)
axes = df.plot(x="x", y="y", subplots=True, sharex=False)
self._check_ticks_props(axes, xrot=0) or even to split them into different tests, and parametrize the parameter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good suggestion, thanks! |
||
|
||
|
||
def _check_plot_works(f, freq=None, series=None, *args, **kwargs): | ||
import matplotlib.pyplot as plt | ||
|
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 am very sorry to be a badass to block your PR, just come across it, can you change
Dataframe
toDataFrame
? 😅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.
😆 good catch, thanks!