Skip to content

Plotting: don't change visibility of xaxis labels and ticklabels if passing in a axis #9740

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

Merged
merged 1 commit into from
Mar 31, 2015

Conversation

jankatins
Copy link
Contributor

This does two things:

  • fix for changing the wrong xlabels/xticklabels if a gridspec is used and the ax is passed in (not sure about using subplot without gridspec)
  • changes the default behaviour for sharex if an axis is passed in: before the visibility changes were applied per default, now they are only applied if explicitly requested via sharex=True

Closes: #9737

@jankatins
Copy link
Contributor Author

Ok, seems that there is a place where the plotting code is tested... will redo...

@jankatins
Copy link
Contributor Author

Ok, fix incoming... rebasing this will be interesting :-(

@jankatins
Copy link
Contributor Author

ok, updated the code and the tests... Let's see...

@jankatins jankatins force-pushed the plotting_with_ax branch 2 times, most recently from 663d47a to 7243211 Compare March 27, 2015 18:56
@jreback jreback added the Visualization plotting label Mar 27, 2015
@jreback jreback added this to the 0.16.1 milestone Mar 27, 2015
@@ -31,6 +31,14 @@ API changes



- When passing in an ax to `df.plot( ..., ax=ax)`, the `sharex` kwarg will now default to `False`.
Copy link
Contributor

Choose a reason for hiding this comment

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

2 backticks instead of 1 to make it render as code

@jankatins
Copy link
Contributor Author

Updated docstrings and fixed whatsnew

self._check_axes_shape(axes, axes_num=3, layout=(3, 1))
#axes[0].figure.savefig("test.png")
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove this line. And another down on line 3587 and 3602

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@TomAugspurger
Copy link
Contributor

Thanks @JanSchulz. I agree that a user passing in an ax should mean they handle more things with the axes labels and we don't try to mess with that.

@sinhrks look good to you?

This commit fixes two things:

1.) Wrong x label visibility when using gridspec generated axis

When using gridspec, plt.gcf().get_axes() was in the wrong order
for the code handling setting the right axes label to invisible.
Also handle cases where no subplot is in the last row of a column.

2.) Don't change ax label visibility when an axis is passed in

Before, when passing in one ax object of a figure with multiple
subplots, the plot call would change the visibility of the x labels,
so that only the subplots in the last row would have xticklabels and
xlabels. This would happen even if the rest of the subplots would
not be plotted with pandas.

Now, when passing in an ax to `df.plot( ..., ax=ax)`, the `sharex`
kwarg will default to `False` and the visibility of xlabels and
xticklabels will not anymore be changed.

If you still want that, you can either do that by yourself for the
right axes in your figure or explicitly set `sharex=True`. Be aware,
that this changes the visible for all axes in the figure, not only
the one which is passed in!

If pandas creates the subplots itself (e.g. no passed in `ax` kwarg),
then the default is still `sharex=True` and the visibility changes are
applied.

Also fix some old unittests which---together with the quirks of
`_check_plot_works`, which plots the plot twice, once without an ax kwarg
and once with an ax kwarg---triggered test failures as the new
behaviour of `ax together without an explicit sharex` would not remove the
visibility of some xlabels.

Update the docstrings to explain the new sharex behaviour and also
add a warning regarding the changing of all subplots' x axis labels,
even for subplots which were not created by pandas.
@jankatins
Copy link
Contributor Author

Squashed and fixed the above comments

@sinhrks
Copy link
Member

sinhrks commented Mar 31, 2015

@JanSchulz @TomAugspurger Looks great!

TomAugspurger pushed a commit that referenced this pull request Mar 31, 2015
Plotting: don't change visibility of xaxis labels and ticklabels if passing in a axis
@TomAugspurger TomAugspurger merged commit 587e410 into pandas-dev:master Mar 31, 2015
@TomAugspurger
Copy link
Contributor

Ok, thanks all.

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

Successfully merging this pull request may close these issues.

plotting: passing in ax is removing the wrong x labels
4 participants