python - How to plot multiple data usind add_axes without over writing existing -


i try create figure zoomed inset graphs, data entire figure (all subplots , insets) plotted @ different positions of code.

to mimic plotting @ different positions in code, minimum (not working) example loops on plotting routine.

the subplots work, insets overwritten each time. inset axes created using add_axes.

i have tried, not create subaxes (add_axes) each time, create them, if not present by:

try:     subax1 except nameerror:     subax1 = fig666.add_axes([0.5,0.71,0.35,0.16])  

this didn't help!

how can fix problem/ conceptual misunderstanding?

thanks help!!!

import matplotlib.pyplot plt import numpy  x_data=numpy.array([0,    1,   1.85,   1.9,  1.95,   2, 2.1, 2.5,   5,  10, 25]) y_data=numpy.array([0,  2.5,    1.8,   0.5,   0.2,  11, 1.2, 0.5, 0.15, 10, 25]) y_data_err=y_data*0.1  number_of_runs=3 iterator in range(number_of_runs):     fig666=plt.figure(666,figsize=(22.0/2.54,18.0/2.54)) #############################     # subplot     ax = plt.subplot(3,1,1)     #ax.plot(x_data,y_data+iterator*0.4,marker=none)                   ax.errorbar(x_data,y_data+iterator*0.4,yerr=y_data_err)     #plt.semilogy()     plt.xlim(1.87,2.25)     plt.ylim(0,3.7)         #####################     #  zoomed inset subplot ##     subax1 = fig666.add_axes([0.5,0.71,0.35,0.16])       #subax1.plot(x_data,y_data+iterator*0.2+0.1,marker=none)                   subax1.errorbar(x_data,y_data+iterator*0.4,yerr=y_data_err)      plt.xlim(1.87,2.25)     plt.ylim(0,3.7) 

is want?

import matplotlib.pyplot plt import numpy  x_data=numpy.array([0,    1,   1.85,   1.9,  1.95,   2, 2.1, 2.5,   5,  10, 25]) y_data=numpy.array([0,  2.5,    1.8,   0.5,   0.2,  11, 1.2, 0.5, 0.15, 10, 25]) y_data_err=y_data*0.1  number_of_runs=3 index_lim=2  iterator in range(number_of_runs):     fig666=plt.figure(666,figsize=(22.0/2.54,18.0/2.54)) #############################     # subplot     ax = plt.subplot(3,1,iterator+1)     ax.plot(x_data,y_data+iterator*0.2,marker=none)                   ax.errorbar(x_data,y_data+iterator*0.2,yerr=y_data_err)     plt.semilogy()       #####################     #  zoomed inset subplot ##     [x0,y0], [x1, y1] = fig666.transfigure.inverted().transform(         ax.transaxes.transform([[0.5, 0.2], [0.95, 0.9]]))     subax1 = fig666.add_axes([x0, y0, x1-x0, y1-y0])       #subax1.plot(x_data,y_data+iterator*0.2+0.1,marker=none)                   subax1.errorbar(x_data,y_data+iterator*0.2,yerr=y_data_err)      subax1.set_xlim(1.87,2.25)     subax1.set_ylim(0,3.7) 

the output:

enter image description here

to create 3 large axes, need change third argument of subplot():

ax = plt.subplot(3,1,iterator+1) 

to create zoom in axes, use transfigure , transaxes transform points in axes points in figure.

[x0,y0], [x1, y1] = fig666.transfigure.inverted().transform(         ax.transaxes.transform([[0.5, 0.2], [0.95, 0.9]])) 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -