-
-
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
Conversation
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.
very nice!
only one nitpick, but could also choose to ignore since it doesn't really matter
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good suggestion, thanks!
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.
can u merge master and ping on green
@jreback ping |
doc/source/whatsnew/v1.1.0.rst
Outdated
@@ -1099,6 +1099,7 @@ Plotting | |||
- Bug in :meth:`DataFrame.boxplot` and :meth:`DataFrame.plot.boxplot` lost color attributes of ``medianprops``, ``whiskerprops``, ``capprops`` and ``medianprops`` (:issue:`30346`) | |||
- Bug in :meth:`DataFrame.hist` where the order of ``column`` argument was ignored (:issue:`29235`) | |||
- Bug in :meth:`DataFrame.plot.scatter` that when adding multiple plots with different ``cmap``, colorbars alway use the first ``cmap`` (:issue:`33389`) | |||
- Bug in :meth:`Dataframe.plot` was rotating xticklabels when subplots was equal to True, even if the x-axis wasn't an irregular time series (:issue:`29460`) |
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
to DataFrame
? 😅
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!
@MarcoGorelli can you move release note to 1.2 |
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.
tiny comment, otherwsie lgtm
doc/source/whatsnew/v1.2.0.rst
Outdated
@@ -239,7 +239,7 @@ I/O | |||
Plotting | |||
^^^^^^^^ | |||
|
|||
- | |||
- Bug in :meth:`DataFrame.plot` was rotating xticklabels when subplots was equal to True, even if the x-axis wasn't an irregular time series (:issue:`29460`) |
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.
use subplots=True
(in double-backticks) so its easily readable
@charlesdong1991 @jorisvandenbossche @TomAugspurger if comments. |
Nothing here.
…On Wed, Aug 12, 2020 at 10:55 AM Jeff Reback ***@***.***> wrote:
@charlesdong1991 <https://github.com/charlesdong1991> @jorisvandenbossche
<https://github.com/jorisvandenbossche> @TomAugspurger
<https://github.com/TomAugspurger> if comments.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#34334 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKAOIXRYE56GRJHYMFDT6LSAK3QZANCNFSM4NIMUDHA>
.
|
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.
lgtm
@MarcoGorelli can you rebase. looks like this was about ready |
thanks for this @MarcoGorelli nice! (and good to add the testing like you did). |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
On
master
, xticklabels are rotated ifThere's a comment saying
, and it seems that the intention was to rotate ticklabels if there's an irregular timeseries.
With the condition as it is written, they will also be rotated if the following is true:
I don't see why that should warrant rotating the ticklabels, so I'd like to suggest that there was a bracketing error.
Also, the condition
data.index.is_all_dates
is (as far as I can tell) only relevant ifuse_index=True
, so I've changed that.Here's what the OP's plot looks like with these changes:
Here's what it looks like on master:
Irregular time series still have their ticklabels rotated:

Regular time series' ticklabels don't rotate:

(unless you pass
xcompat=True
, but that's unaffected by this change)