0

I have a function named make_plot that takes as an input a list of matrices of length 15 and outputs a plot that is a 3x5 collection of heatmaps (one for each of the matrices in the list).

I would then like to display the output of this function applied to two different lists of matrices, showing the output side-by-side.

I thought this was just a simple application of matplotlib subplots, as discussed here: https://matplotlib.org/stable/gallery/subplots_axes_and_figures/subplots_demo.html

However, I haven't figured out how to get the output of my custom function make_plot to fit into the subplots that I would like.

For example, the provided code on the matplotlib site for how to make horizontal plots is

fig, (ax1, ax2) = plt.subplots(1, 2)
fig.suptitle('Horizontally stacked subplots')
ax1.plot(x, y)
ax2.plot(x, -y)

But if I try a gentle modification like

fig, (ax1, ax2) = plt.subplots(1, 2)
fig.suptitle('Horizontally stacked subplots')
ax1 = make_plot(mats1)
ax2 = mate_plot(mats2)

I get two empty plots, and then the usual outputs of make_plot stacked on top of each other.

I feel like there is something I'm not really understanding about the nature of matplotlib objects, this seems like it should be a simple / reasonable thing to do, but I haven't figured out how to do it yet. Any pointers would be so appreciated!

  • Would be helpful to share the code for `mate_plot`, but I'd recommend passing an `Axes` parameter to it. – BigBen Sep 19 '22 at 20:27
  • 1
    *really* difficult to give concrete advice when all we can do is imagine what `make_plot` does. generally speaking: it should accept an Axes instance as input and it should operate on the instance directly as opposed to using the general `pyplot` API. – Paul H Sep 19 '22 at 20:28
  • 1
    Does this answer your question? [Adding a figure created in a function to another figure's subplot](https://stackoverflow.com/questions/65618035/adding-a-figure-created-in-a-function-to-another-figures-subplot) – BigBen Sep 19 '22 at 20:34

0 Answers0