You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Suptitle not visible with subfigures #24910
I don't think we specifically set the background color of subfigures to anything different than a figure, which defaults to white. We could, by default, make subfigures transparent, but not 100% clear to me that is the right thing to do.
FWIW, this problem goes away with layout='constrained' which makes the subfigure the correct size to allow the suptitle.
We could, by default, make subfigures transparent, but not 100% clear to me that is the right thing to do.
I agree that this could have the potential to add unpredictable complexity, but in practice what do you think the failure mode would look like?
If the default subfigure facecolor is transparent, it will appear as if the overlying subfigures have whatever facecolor is set for figures by default (i.e. in the rc params), so changing the figure default will still "work". And you could still have subfigures listen to the facecolor parameter passed when they are created, so users could make a subfigure within a larger figure that has a distinct background.
The only potential confusing situation that comes to mind is if a user set the rc parameter to a specific value, set the figure facecolor to a different value, and then expects a subfigure made without an explicit facecolor to follow the rc parameter rather than inherit from the parent. While that strikes me as unusual (I think I would maybe expect inheritance? but not sure) it seems like there's an easy route to the solution ("ah, it's inheriting the parent figure color, so let me try setting the facecolor when I create the subfigure").
In contrast, the root cause of the behavior here is not obvious; it just looks like the suptitle "isn't working" for some reason. Note how the seaborn issue was presented, it appeared to the user (who is sharp) that the suptitle was "being removed". It took me a while to determine that it's actually there, just "under" the subfigure (especially since zorder didn't work, which I tried first).
And while it's good to know that constrained_layout will help with suptitle, I don't think tight_layout accounts for suptitles, and neither layout engine handles similar edge cases like manually added text artists representing captions or panel labels. (Right?)
So on balance, I think that making subfigures have transparent facecolors by default will strictly reduce surprise, but maybe I'm not thinking of a circumstance where that's not true.
Ah, so that was what happened. I was really confused by the issue as I could still see that the Text object was correctly in the fig.texts ; I had also tried moving it around in the figure and it did not work, probably because it was still under the subfigures (although in my case I thought that I was using the constrained layout while seaborn actually deactivated it, which added to the confusion).
I do agree that this is definitely an easy trap to fall in for which I would not expect a non-expert user to quickly find the solution (using constrained layout). There is probably a way to make the suptitle show above the subfigures anyway but it does not seem obvious to me ; I agree with the case for having transparent subfigures (but could be missing something as well).
neither layout engine handles similar edge cases like manually added text artists representing captions or panel labels. (Right?)
I'm not sure what you mean by this - certainly if you attach text to an axes, constrained_layout will make all the axes smaller to make sure there is no overlap, just like it does for titles and ticklabels...
For this particular issue, I think someone could easily put in a PR to make the default facecolor for subfigures "none" and see what people think. I agree it's probably fine for 99.9% of cases, and easy to change to something else if desired. I'll mark as a good first issue and I don't think its hard, though anyone interested in pursuing should be prepared to advocate for it.
Yeah — there's a separate issue about adding a Figure.caption concept that layout algorithms could then be smart about (#23873) but the point here is that there are other edge cases for this issue that are not solved even by non-default "best practices".
Activity
jklymak commentedon Jan 8, 2023
I don't think we specifically set the background color of subfigures to anything different than a figure, which defaults to white. We could, by default, make subfigures transparent, but not 100% clear to me that is the right thing to do.
FWIW, this problem goes away with
layout='constrained'which makes the subfigure the correct size to allow the suptitle.mwaskom commentedon Jan 9, 2023
I agree that this could have the potential to add unpredictable complexity, but in practice what do you think the failure mode would look like?
If the default subfigure facecolor is transparent, it will appear as if the overlying subfigures have whatever facecolor is set for figures by default (i.e. in the rc params), so changing the figure default will still "work". And you could still have subfigures listen to the
facecolorparameter passed when they are created, so users could make a subfigure within a larger figure that has a distinct background.The only potential confusing situation that comes to mind is if a user set the rc parameter to a specific value, set the figure facecolor to a different value, and then expects a subfigure made without an explicit facecolor to follow the rc parameter rather than inherit from the parent. While that strikes me as unusual (I think I would maybe expect inheritance? but not sure) it seems like there's an easy route to the solution ("ah, it's inheriting the parent figure color, so let me try setting the facecolor when I create the subfigure").
In contrast, the root cause of the behavior here is not obvious; it just looks like the suptitle "isn't working" for some reason. Note how the seaborn issue was presented, it appeared to the user (who is sharp) that the suptitle was "being removed". It took me a while to determine that it's actually there, just "under" the subfigure (especially since zorder didn't work, which I tried first).
And while it's good to know that constrained_layout will help with suptitle, I don't think tight_layout accounts for suptitles, and neither layout engine handles similar edge cases like manually added text artists representing captions or panel labels. (Right?)
So on balance, I think that making subfigures have transparent facecolors by default will strictly reduce surprise, but maybe I'm not thinking of a circumstance where that's not true.
thuiop commentedon Jan 9, 2023
Ah, so that was what happened. I was really confused by the issue as I could still see that the Text object was correctly in the fig.texts ; I had also tried moving it around in the figure and it did not work, probably because it was still under the subfigures (although in my case I thought that I was using the constrained layout while seaborn actually deactivated it, which added to the confusion).
I do agree that this is definitely an easy trap to fall in for which I would not expect a non-expert user to quickly find the solution (using constrained layout). There is probably a way to make the suptitle show above the subfigures anyway but it does not seem obvious to me ; I agree with the case for having transparent subfigures (but could be missing something as well).
anntzer commentedon Jan 9, 2023
Not that it really matters for the discussion here, but
has been fixed in #17219.
jklymak commentedon Jan 9, 2023
Just to clarify - suptitles now works for simple cases that tight_layout works on. However it does not work for subfigures or other nested layouts.
jklymak commentedon Feb 8, 2023
I'm not sure what you mean by this - certainly if you attach text to an axes, constrained_layout will make all the axes smaller to make sure there is no overlap, just like it does for titles and ticklabels...
For this particular issue, I think someone could easily put in a PR to make the default facecolor for subfigures "none" and see what people think. I agree it's probably fine for 99.9% of cases, and easy to change to something else if desired. I'll mark as a good first issue and I don't think its hard, though anyone interested in pursuing should be prepared to advocate for it.
mwaskom commentedon Feb 8, 2023
I would typically specify panel labels or a caption by adding text to the figure object, not the axes:
jklymak commentedon Feb 8, 2023
Yes I see. Definitely the layout engines cannot avoid random figure objects, so space would have to be reserved for a "caption" like this.
mwaskom commentedon Feb 9, 2023
Yeah — there's a separate issue about adding a
Figure.captionconcept that layout algorithms could then be smart about (#23873) but the point here is that there are other edge cases for this issue that are not solved even by non-default "best practices".robrighter commentedon Feb 19, 2023
I created a pull request to satisfy the suggested solution above. This makes "none" the default facecolor for subfigures:
#25255
RR - Set default facecolor for subfigures to be none (Transparent). F…
RR - Set default facecolor for subfigures to be none (Transparent). F…
Make default facecolor for subfigures be transparent ("none"). Fix fo…
Make default facecolor for subfigures be transparent ("none"). Fix fo…
Make default facecolor for subfigures be transparent ("none"). Fix fo…
Make default facecolor for subfigures be transparent ("none"). Fix fo…