Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ENH: Subfigures#18356

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
QuLogic merged 1 commit intomatplotlib:masterfromjklymak:enh-subpanels
Oct 9, 2020
Merged

ENH: Subfigures#18356

QuLogic merged 1 commit intomatplotlib:masterfromjklymak:enh-subpanels
Oct 9, 2020

Conversation

jklymak
Copy link
Member

@jklymakjklymak commentedAug 25, 2020
edited
Loading

PR Summary

This PR re-introduces subfigures:

importmatplotlib.pyplotaspltimportnumpyasnpdefexample_plot(ax,fontsize=12,hide_labels=False):pc=ax.pcolormesh(np.random.randn(30,30))ifnothide_labels:ax.set_xlabel('x-label',fontsize=fontsize)ax.set_ylabel('y-label',fontsize=fontsize)ax.set_title('Title',fontsize=fontsize)returnpc# gridspec inside gridspecfig=plt.figure(constrained_layout=True,figsize=(10,4))subfigs=fig.subfigures(1,2,wspace=0.07)axsLeft=subfigs[0].subplots(1,2,sharey=True)subfigs[0].set_facecolor('0.75')foraxinaxsLeft:pc=example_plot(ax)subfigs[0].suptitle('Left plots',fontsize='x-large')subfigs[0].colorbar(pc,shrink=0.6,ax=axsLeft,location='bottom')axsRight=subfigs[1].subplots(3,1,sharex=True)fornn,axinenumerate(axsRight):pc=example_plot(ax,hide_labels=True)ifnn==2:ax.set_xlabel('xlabel')ifnn==1:ax.set_ylabel('ylabel')subfigs[1].colorbar(pc,shrink=0.6,ax=axsRight)subfigs[1].suptitle('Right plots',fontsize='x-large')fig.suptitle('Figure suptitle',fontsize='xx-large')plt.show()

Subpanles

Subfigures are created via:fig.subfigures (likefig.subplots) andfig.add_subfigure (likefig.add_subplots). Before these would have been added withGridspecFromSubgridspec objects and those objects would not have had the ability to have subtitles, or their own legends.

Subfigures are basically figures without the figure management. Anything you can add to a figure you can add to a sub-panel. That required significant refactoring infigure.py where all the artist methods infigure.py are movedFigureBase, and thenSubFigurel andFigure are subclasses.

This is relatively major surgery tofigure.py though the newFigure class should be exactly the same as the old one.

Test Changes:

  • test_polar.py: Increased tolerance for two annotation tests
  • test_plot_3d_from_2: increased tolerance from 0.01 to 0.015.
  • A few 3-d axes had:ax=Axes3D(fig); previouslyAxes3D.__init__ would add the axes to the figure (which is not an unreasonable expectation, but not one that is supported byAxes). This caused the axes to be added twice to the figure. So that extrafig.add_axes has been removed inAxes3D.__init__ and the two tests in the suite that used that grammar were changed to explicitly add the axes:ax=Axes3D(fig); fig.add_axes(ax).

PR Checklist

  • it fails the image tests with colorbars for some unknown reason. I'll track that down.
  • It needs more documentation
  • it needs tests
  • use this forsubplot_mosaic?

mwaskom, story645, and MaozGelbart reacted with thumbs up emoji
@jklymakjklymak added topic: geometry managerLayoutEngine, Constrained layout, Tight layout status: needs comment/discussionneeds consensus on next step labelsAug 25, 2020
@timhoffm
Copy link
Member

timhoffm commentedAug 26, 2020
edited
Loading

I haven't yet looked into the details, but the overall idea seems reasonable. What is the motivation to name this "SubPanel"? IMHO just "Panel" would be simpler and is equally expressive.

story645 reacted with thumbs up emoji

@jklymak
Copy link
MemberAuthor

subpanel was meant to be evocative ofsubplot, which this is directly analogous to. i.e thesubpanel slots into a figure exactly the same way asubplot does. Not completely against the idea of just calling it apanel, but it really is meant to be a subordinate part of a larger figure, so I thinksub makes sense.

One thing I should have mentioned above is that this is recursive. i.e. asubpanel can be added inside asubpanel, etc etc. So@QuLogic was making slides with matplotlib - this would have been a lot easier if he'd had subpanels to work with.

@timhoffm
Copy link
Member

https://en.wikipedia.org/wiki/Panel#Visual_arts

Panel (comics), a single image in a comic book, comic strip or cartoon [...]
Panel painting, in art, either one element of a multi-element piece of art, such as a triptych [...]

To me, there's enough "sub" notion inpanel already without explicitly naming it.

@jklymak
Copy link
MemberAuthor

I agree with you that a panelcan be a subdivision. Or it can be a single thing.

https://www.merriam-webster.com/dictionary/panel
https://en.wikipedia.org/wiki/Panel#Science_and_technology

The argument for addingsub is to make it rhyme withsubplots, where thesub is also arguably redundant. So right now you can do:

fig=plt.figure()gs=fig.add_gridspec(2,1)# LHSax=fig.add_subplot(gs[0])#RHSpanel=fig.add_subpanel(gs[1])subaxs=panel.subplots(2,2)

Originally, it wassubfigure, but somewhere along the line that got rejected...

@tacaswell
Copy link
Member

I am very 👍 on this in principle.

@jklymak
Copy link
MemberAuthor

Ok, so I moved a bunch of methods fromFigure.foo toPanelBase.foo, andFigure is now a subclass ofPanelBase. Which shouldn't matter, except Sphinxautosummary :: can no longer findFigure.foo and saysreference target not found: Figure.foo. I don't think we want to change every instance ofFigure.foo, though I guess I could. Is there no way to get sphinx to allow the subclass to reference its parent?

@mwaskom
Copy link

@jklymak
Copy link
MemberAuthor

Yes Absolutley. I already have a pr for that but dont want to rebase it all the time.

mwaskom reacted with hooray emoji

@mwaskom
Copy link

Awesome! Also, regarding the name, I feel like when discussing figures in journal articles, "panel" is the term often used for what in matplotlib would be a called a subplot or axes, e.g. "Panel (A) shows the mean frobexity over time, Panel (B) shows blah blah blah". Having "subpanel" be concept that is actually super-ordinate to that object might be confusing...

jklymak reacted with thumbs up emoji

@jklymak
Copy link
MemberAuthor

jklymak commentedSep 16, 2020
edited
Loading

Originally, it was justsubfigure - I've lost where it was discussed and rejected as a name, but I'd actually prefer it as the inheritance would then beFigure(FigureBase) andSubFigure(FigureBase) (ahem, plus or minus the currently unfashionable camel-case).

Edit: but open to other names as well...

@jklymak
Copy link
MemberAuthor

Thanks to some help I got the docs to build. Thanks@larsoner. Thisdoes change thefigure_api.rst to be monolithic however, as that was how I was able to get the inherited members to build properly. Anyone with better experience with autodoc is welcome to subsequently re-organize.

This needs input for the name, otherwise ready-is to go....subpanel,panel,subfigure, others???

@jklymak
Copy link
MemberAuthor

As pointed out by@story645 on gitter,subfigure is also used in Latexsubfig package....

@jklymak
Copy link
MemberAuthor

There is a user-contributed matlab subfigure, but it is a window tiler (not something I think we should have ;-)https://www.mathworks.com/matlabcentral/fileexchange/23426-subfigure

@tacaswelltacaswell added this to thev3.4.0 milestoneSep 21, 2020
@jklymak
Copy link
MemberAuthor

On call we decided thatsubfigure should be the new name.

Also noted that need to make sureAnnotate andConnectionPatch work on subFigure.

@jklymakjklymak changed the titleENH: SubpanelsENH: SubfiguresSep 21, 2020
@jklymakjklymakforce-pushed theenh-subpanels branch 2 times, most recently from9f6e0e6 to1dd462dCompareSeptember 21, 2020 23:06
@jklymakjklymak removed the status: needs comment/discussionneeds consensus on next step labelSep 21, 2020
@jklymakjklymakforce-pushed theenh-subpanels branch 2 times, most recently from7e91ab1 to5752a94CompareSeptember 21, 2020 23:48
@jklymak
Copy link
MemberAuthor

Is it worth adding an example that mixes Axes and SubFigures at the same level in the host Figure?

Example was expanded. Which was good, because I had a bug in the suptitle placement code....

@jklymakjklymakforce-pushed theenh-subpanels branch 2 times, most recently from8a73a4b to835175bCompareSeptember 30, 2020 05:03
@jklymak
Copy link
MemberAuthor

@tacaswell Just one main enquiry for you about the compositing of images... Not sure I understood the comment.

@jklymakjklymakforce-pushed theenh-subpanels branch 5 times, most recently from454f97f toe373a36CompareOctober 4, 2020 15:16
Copy link
Member

@efiringefiring left a comment

Choose a reason for hiding this comment

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

My review is somewhat cursory and raises only few minor questions.

axsLeft = subfigs[0].subplots(1, 2, sharey=True)
subfigs[0].set_facecolor('0.75')
for ax in axsLeft:
pc = example_plot(ax)
Copy link
Member

Choose a reason for hiding this comment

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

Indentation is off.

jklymak reacted with thumbs up emoji
is used and `.projections.polar.PolarAxes` if polar projection
is used. The returned axes is then a subplot subclass of the
are used and `.projections.polar.PolarAxes` if polar projection
are used. The returned axes is then a subplot subclass of the
Copy link
Member

Choose a reason for hiding this comment

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

The "are" instances were correct before as "is".

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Thats a strange one. I don't think I changed that. Maybe I missed it in a rebase? Anyhow, fixed....

for examples. (Note: does not work with `add_subplot` or
`~.pyplot.subplot2grid`.)
"""
def __init__(self):
super().__init__()
# remove the non-figure artist _axes property
# as it makes no sense for a figure to be _in_ an axes
# this is used by the property methods in the artist base class
# which are over-ridden in this class
Copy link
Member

Choose a reason for hiding this comment

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

Why did you leave the comment, but move the deletion to the subclass? Doesn't the deletion make sense as a base class operation?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Agreed. re-added the deletion in the base class and removed it fromclass Figure.

Copy link
Member

@QuLogicQuLogic left a comment

Choose a reason for hiding this comment

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

It is difficult to find a place to comment on it, but thelegend docstring seems to be missing the Call signatures, the 3 examples of them, and the See Also section.

@jklymak
Copy link
MemberAuthor

Thanks@QuLogic - I still have to look at the legend issue, so I'll mark as draft until I sort that out.

@jklymakjklymak marked this pull request as draftOctober 7, 2020 20:04
@jklymak
Copy link
MemberAuthor

OK think I fixed up legend:https://47262-1385122-gh.circle-artifacts.com/0/doc/build/html/api/figure_api.html#matplotlib.figure.Figure.legend Again, I must have missed that in a rebase...

@jklymakjklymak marked this pull request as ready for reviewOctober 8, 2020 01:56
Copy link
Member

@QuLogicQuLogic left a comment

Choose a reason for hiding this comment

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

Hopefully last round, I think.

def get_size_inches(self):
return self._parent.get_size_inches()

def get_constrained_layout(self):
Copy link
Member

Choose a reason for hiding this comment

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

These two could get a docstring, then?

jklymak reacted with thumbs up emoji
@jklymakjklymakforce-pushed theenh-subpanels branch 2 times, most recently from10da45d tof542c0bCompareOctober 8, 2020 16:30
Copy link
Member

@QuLogicQuLogic left a comment

Choose a reason for hiding this comment

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

One remaining typo.

Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
@QuLogicQuLogic merged commit3b1be53 intomatplotlib:masterOct 9, 2020
@QuLogic
Copy link
Member

OK, let's see how this goes...

@jklymakjklymak deleted the enh-subpanels branchOctober 9, 2020 13:19
@jklymak
Copy link
MemberAuthor

Thanks a lot@QuLogic,@efiring and@tacaswell!

@QuLogic, hopefully this helps when you make your next all-matplotlib slide deck ;-)

TomDLT reacted with hooray emoji

@tacaswell
Copy link
Member

🎉

I swear reviewing this was on my todo list....

timhoffm reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell left review comments

@efiringefiringefiring approved these changes

@QuLogicQuLogicQuLogic approved these changes

Assignees
No one assigned
Labels
topic: geometry managerLayoutEngine, Constrained layout, Tight layout
Projects
None yet
Milestone
v3.4.0
Development

Successfully merging this pull request may close these issues.

6 participants
@jklymak@timhoffm@tacaswell@mwaskom@QuLogic@efiring

[8]ページ先頭

©2009-2025 Movatter.jp