Thanks to visit codestin.com
Credit goes to github.com

Skip to content

SubFigure in Proplot? #291

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

Closed
pratiman-91 opened this issue Oct 5, 2021 · 3 comments
Closed

SubFigure in Proplot? #291

pratiman-91 opened this issue Oct 5, 2021 · 3 comments

Comments

@pratiman-91
Copy link
Contributor

Description

Is it possible to use Matplotlib SubFigure for proplot?

I think it needs a separate subfigure class to be utilized in proplot.

For example

import matplotlib.pyplot as plt
import numpy as np

def example_plot(ax, fontsize=12, hide_labels=False):
    pc = ax.pcolormesh(np.random.randn(30, 30), vmin=-2.5, vmax=2.5)
    if not hide_labels:
        ax.set_xlabel('x-label', fontsize=fontsize)
        ax.set_ylabel('y-label', fontsize=fontsize)
        ax.set_title('Title', fontsize=fontsize)
    return pc

fig = plt.figure(constrained_layout=True, figsize=(10, 4))
subfigs = fig.subfigures(1, 2, wspace=0.07, width_ratios=[2, 1])

axsLeft = subfigs[0].subplots(1, 2, sharey=True)
subfigs[0].set_facecolor('0.75')
for ax in axsLeft:
    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)
for nn, ax in enumerate(axsRight):
    pc = example_plot(ax, hide_labels=True)
    if nn == 2:
        ax.set_xlabel('xlabel')
    if nn == 1:
        ax.set_ylabel('ylabel')

subfigs[1].set_facecolor('0.85')
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()

Expected behavior: [Matplotlib Plot]
image

Actual behavior: [Same code with Proplot]
image

Proplot version

matplotlib: 3.4.3
proplot: 0.9.2

@lukelbd lukelbd added the feature label Oct 5, 2021
@lukelbd
Copy link
Collaborator

lukelbd commented Oct 8, 2021

Unfortunately I think subfigures are too conflicting with proplot's paradigms and redundant with proplot features to support. Here are my reasons:

  1. Subfigures seem to primarily be an extension of GridSpecFromSubplotSpec, which proplot does not explicitly support. Instead, if you want certain subplots to appear "grouped together", you can create a GridSpec with vector-input wspace and hspace (e.g., the above example could be something like GridSpec(ncols=3, nrows=3, wspace=(1, 3))).
  2. Subfigures seem to be potentially useful for making subplots with different "styles", but SubplotGrid combined with the format command makes it pretty straightforward to style individual subplots or subplot groups differently.
  3. It seems ambiguous how a-b-c labels should be assigned for subplots inside subfigures. This would be a whole can of worms we have to figure out.
  4. It seems that unlike GridSpecFromSubplotSpec, the subplot edges in each "subfigure" can be misaligned. But I don't really see how this is useful... it just looks kind of messy tbh.
  5. It would be useful to "concatenate" or save individual subfigures, but matplotlib does not seem to allow this (I might implement this in proplot some day -- Add function for "concatenating" figures #203).

So, it seems like most subfigure features can be reproduced in proplot already. Maybe I'll add a note in the documentation about how SubFigure and GridSpecFromSubplotSpec are not officially supported.

Let me know if there's any subfigure use cases I'm missing here.

@lukelbd lukelbd closed this as completed Oct 8, 2021
@lukelbd lukelbd added the wontfix label Oct 8, 2021
@lukelbd
Copy link
Collaborator

lukelbd commented Oct 8, 2021

One last "subfigure" feature that I can see being useful is adding shading behind different groups of subplots (like in your example). Come to think of it I've actually had to do this before. But this could definitely fall under the umbrella of the format command. I'll add it to my to-do list. Could be something like highlightcolor or backgroundcolor.

@pratiman-91
Copy link
Contributor Author

  • Seems logical. Maybe adding into the documentation might be helpful. Thanks!
  • Regarding concatenation of the figures is of particular interest to me. There are several instances where I had generated several figures but lacked a straightforward method to concatenate all of them into a single figure.

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

No branches or pull requests

2 participants