Skip to content

Conversation

@glemaitre
Copy link
Contributor

@glemaitre glemaitre commented Sep 1, 2023

@glemaitre glemaitre marked this pull request as draft September 1, 2023 20:54
@glemaitre glemaitre changed the title BUG handle sharey with horizontal plot.box BUG df.plot.box handles matplotlib Axes with sharey=True Sep 1, 2023
@glemaitre glemaitre marked this pull request as ready for review September 1, 2023 21:46
@glemaitre
Copy link
Contributor Author

glemaitre commented Sep 1, 2023

I think this is a first fix. However, there is still a discrepancy between df.boxplot and df.plot.box:

df.plot.box

image

df.boxplot

image

On the df.plot.box, the minor ticks are visible mainly due to calling this function:

def _remove_labels_from_axis(axis: Axis) -> None:
for t in axis.get_majorticklabels():
t.set_visible(False)
# set_visible will not be effective if
# minor axis has NullLocator and NullFormatter (default)
if isinstance(axis.get_minor_locator(), ticker.NullLocator):
axis.set_minor_locator(ticker.AutoLocator())
if isinstance(axis.get_minor_formatter(), ticker.NullFormatter):
axis.set_minor_formatter(ticker.FormatStrFormatter(""))
for t in axis.get_minorticklabels():
t.set_visible(False)
axis.get_label().set_visible(False)

The plt.boxplot will not create the minor ticks but with the plot accessor, the _adorn_subplots is calling handle_shared_axes that is calling the function above and somehow recreating the minor ticks.

I would leave this issue for another PR because touching this part should have some other side effect on other plots.

@mroeschke mroeschke added the Visualization plotting label Sep 5, 2023
@mroeschke mroeschke added this to the 2.2 milestone Sep 18, 2023
@mroeschke mroeschke merged commit 66a4945 into pandas-dev:main Sep 18, 2023
@mroeschke
Copy link
Member

Thanks @glemaitre

hedeershowk pushed a commit to hedeershowk/pandas that referenced this pull request Sep 20, 2023
…54940)

* BUG manage sharey in plot.box with vert=False

* fix

* add entry in whats new

* iter
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.

BUG: df.plot.box does not handle well when matplotlib Axes uses sharey=True

2 participants