0

I have a method that returns an array of matplotlib.figure.Figure objects, I call pyplot.close() afterwards an keep the objects. I want to redraw those Figure objects as subplots of one Figure.

It looks like this

import matplotlib.pyplot as plt
FIGS = list()
for indx, i in enumerate(HISTARR):
    FIGS.append(subHistogramClientWrapper(indx, LIST, HISTARR.size(), i))
plt.close()
for each in FIGS:
    plt.draw()
plt.show()
## This code below will crash, since add_subplot can't receive a figure
figo_help_me = plt.figure(1, figsize=(12, 3))
for each in FIGS:
    figo_help_me.add_subplot(each)
plt.show()

Should I return one figure with subplots?

If so, how do I redraw a figure after calling plt.close()?

Saullo G. P. Castro
  • 56,802
  • 26
  • 179
  • 234
Claudiordgz
  • 3,023
  • 1
  • 21
  • 48
  • Moving artists between figures is hard. You should refactor your code to take the axes to draw to as an argument. – tacaswell Jul 31 '13 at 16:58
  • The algorithm returns an array of ranges, then I create several histograms for the same dataset using different ranges. That is why I created the subHistogramClientWrapper. I just wanted to know if there was a better way to store and re draw the figures. – Claudiordgz Jul 31 '13 at 17:27
  • right, pass the axes you want `subHistogramClientWrapper` to draw to as an argument, instead of having it create and return `figure` objects. – tacaswell Jul 31 '13 at 17:51
  • @tcaswell, you suggested the same solution in the other thread. The Wrapper already does what you say, that's the purpose of it, but if my client needs the figures then I don't see the point of redrawing (in case the data array is too large >50k). I think the best solution will be to use numpy histograms to recalculate using the large dataset and then store the axis as you say since redrawing a figure object is not feassible. – Claudiordgz Jul 31 '13 at 18:54
  • no, your wrapper creates and returns `figure` objects (which you shove into the list called `FIGS`) which is _not_ what I am suggesting. Set up the axes you want _first_ and pass the resulting `axes` objects into your wrapper function. – tacaswell Jul 31 '13 at 18:59
  • You should also read http://stackoverflow.com/questions/14254379/how-can-i-attach-a-pyplot-function-to-a-figure-instance/14261698#14261698 as you have some confusion about what `plt.*` does. – tacaswell Jul 31 '13 at 19:08
  • Thank you @tcaswell, I removed the return from the wrapper. I shall handle everything with both axes. The thread you place has some really interesting information. regards – Claudiordgz Jul 31 '13 at 22:13

0 Answers0