Creating two completely independent graphs in matplotlib and moving between them

I would like to create two independent matplotlib graphics in a python script and potentially jump between them by adding lines, annotations, etc. to different graphs (for example, maybe I call a function that adds lines to both plots, and then another function that adds annotations).

I expect that by working out the matplotlib examples, I could figure out some solution that works, but I would like to know what is the preferred and cleanest way to do this. I am embarrassed when I have to do something like

fig,ax=plt.subplots()

and when I will do things like:

fig=plt.figure()

Also, how should I switch between graphs. If I did something like

fig1,ax1=plt.subplots()
fig2,ax2=plt.subplots()

Is it possible to simply reference these graphs by doing something like:

ax1.plt.plot([some stuff])
ax2.plt.plot([otherstuff]

? , matplotlib plt.subplot(),

plt.plot([stuff])

, -, , ax1 ax2, . , -

plt.savefig(....)

. , ?

+3
1

, , .

, . , plt.subplots() , , plt.figure() .

. , :

fig, ax = plt.subplots()

fig = plt.figure()
ax = fig.add_subplot(111)

, , , . , :

fig = plt.figure()
ax = fig.add_axes([.1, .1, .2, .8])

.


, ?

subplots , ( (1, 1). , , ,

fig, axes = plt.subplots(1, 2)

axes (1, 2), Axes. Python :

fig, (ax1, ax2) = plt.subplots(1, 2)

, , MATLAB?

pyplot Figure Axes. Matplotlib ( MATLAB) "" . plt.plot, ( ). plt.savefig, .

, - . , , , , (, ), , , , , . , , - , , , .

+4

All Articles