79239609

Date: 2024-11-30 13:20:01
Score: 1
Natty:
Report link

If you want to plot in a specific figure number your figure using fig1 = plt.figure(1), fig2 = plt.figure(2) etc. To plot a graph in a specific figure define axes ax1 = fig1.gca() gca = get current axis and instead of using plt.plot() use ax1.plot() to plot in the figure 1

import matplotlib.pyplot as plt

x1 = [0,1] x2 = [0,2]

y1 = [0,1] y2 = [0,-1]

fig1 = plt.figure(1) ax1 = fig1.gca()

fig2 = plt.figure(2) ax2 = fig2.gca()

ax1.plot(x1,y1,'b') ax2.plot(x2,y2,'r')

plt.show() If you want to create 5 figures use lists :

fig = [] ax = [] for i in range(5) : fig.append(plt.figure(i)) ax.append(fig[i].gca()) if the figure 1 is already opened and you want to plot an additional curve you just have to type these lines :

fig3 = plt.figure(1) ax3 = fig1.gca() ax3.plot(x1,y2,'g') fig3.canvas.draw()

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Aseel S