How do I include a matplotlib Figure object as subplot? -


this question has answer here:

how can use matplotlib figure object subplot? specifically, have function creates matplotlib figure object, , include subplot in figure.

in short, here's stripped-down pseudocode i've tried:

    fig1 = plt.figure(1, facecolor='white')     figa = myseparateplottingfunc(...)     figb = myseparateplottingfunc(...)     figc = myseparateplottingfunc(...)     figd = myseparateplottingfunc(...)     fig1.add_subplot(411, figure=figa)     fig1.add_subplot(412, figure=figb)     fig1.add_subplot(413, figure=figc)     fig1.add_subplot(414, figure=figd)     fig1.show() 

sadly, however, fails. know fact individual plots returned function invocations viable--i did figa.show(),...,figd.show() confirm ok. final line in above code block--fig1.show()--is collection of 4 empty plots have frames , x- , y- tickmarks/labels.

i've done quite bit of googling around, , experimented extensively, it's clear i've missed either subtle, or embarrassingly obvious (i'll happy latter long can un-stuck).

thanks advice can offer!

you can't put figure in figure.

you should modify plotting functions take axes objects argument.

i unclear why kwarg figure there, think artifact of way inheritance works, way documentation auto-generated, , way of getter/setter work automated. if note, says figure undocumented in figure documentation, might not want;). if dig down bit, kwarg controls figure created axes attached too, not want.

in general, moving existing axes/artists between figures not easy, there many bits of internal plumbing need re-connected. think can done, involving touching internals , there no guarantee work future versions or warning if internals change in way break it.

you need plotting functions take axes object argument. can use pattern like:

def myplotting(..., ax=none):     if ax none:         # existing figure generating code         ax = gca() 

so if pass in axes object gets drawn (the new functionality need), if don't of old code work expected.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -