0

I have a number of functions that return figures, like

def create_predef_plot():
    f, ax = plt.subplots()
    ax.plot(randn(10))
    return f, ax

how can i insert the plot returned by create_predef_plot into f2

plot1 = create_predef_plot()
f2, (ax21, ax22) = subplots(1,2)
greole
  • 4,523
  • 5
  • 29
  • 49
  • http://stackoverflow.com/questions/18284296/matplotlib-using-a-figure-object-to-initialize-a-plot/18302072#18302072 may be of interest – tacaswell Nov 25 '13 at 04:33

1 Answers1

1

1) this has nothing to do with IPython, it is pure matplotlib

2) the common pattern is to use an ax keyword argument.

def create_predef_plot( ax=None ):
    if not ax
        f, ax = plt.subplots()
    ax.plot(randn(10))
    return ax


f2, (ax21, ax22) = subplots(1,2)
create_predef_plot(ax=ax22)
Matt
  • 27,170
  • 6
  • 80
  • 74