-
-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
BUG: inconsistent subplot ax handling #7391
Conversation
And it revealed that current |
Sorry. Going to be traveling for a while. Il'l chip in when I can but I won't be too reliable.
|
i'll take a look |
@sinhrks can you throw up a couple of plots and some code to demonstrate the issue? thx |
so this fixes the single |
@cpcloud The fix will preserve the existing figure on single axes, not for multiple axes. And it makes Example code and result using current master is attached below.
|
For the single ax case, I completely agree it is a bug right now that the axes is cleared when passing But for the multiple axes case, is it also an option to go with raising an Error? In the reasoning that if a user passes an axes object with already a plot on (that would be cleared) or that does not match the number of subplots, he has done something wrong and maybe wants to be notified of that? |
If it raises error in subplot case, there will be no way to specify target figure. Thus, warning is better to show passed ax is being flushed. |
Maybe always warn when something is cleared? (I think we should always warn if something gets cleared, but the problems is now of course that you can also provide an empty ax, so not necessary in that case to warn) Would it be possible to let the user also pass the figure in those cases instead of an axes object that will be removed anyway? |
@sinhrks Did you change something in your last update? |
Not yet, going to add warning message in multiple subplots case and test. From my understanding, warning should always be displayed in these cases, because And I prefer to passing list of axes in future, not figure. Going to work on separate PR. |
return fig, _flatten(ax) | ||
else: | ||
warnings.warn("To output multiple subplots, the figure contains passed axes " | ||
"is being cleared", UserWarning) |
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.
This sentence does not seem fully correct sentence. Did you mean "the figure containing the passed axes"?
Apart from my small comment, is this ready to merge? |
@jorisvandenbossche Thanks, modified the warning message. I hope the work has been finished if there is no other points. |
Not for my part, @cpcloud any further comments? |
@sinhrks looks ok, @cpcloud @jorisvandenbossche any comments? |
BUG: inconsistent subplot ax handling
There is an inconsistency
DataFrame.plot
,hist
andboxplot
when subplot enabled (subplots=True
or useby
kw).Current behaviour
plot
andhist
:When
ax
kw is passed, plot will be drawn on the figure which the passed ax belongs. The figure will be once cleared even if the required number of subplot is 1. Thus, any artists contained in the passedax
will be flushed.box
:When
ax
kw is passed and a required number of subplots is 1, use the passedax
without clearing the existing plot. If more than 1 axes is required for the subplots, raisesValueError
.Fix
ax
kw is passed and a required number of subplots is 1, use the passedax
without clearing the existing plot.