您好我正在尝试同时绘制两件事。我不希望他们在同一个情节。以下是第一个情节的代码:
gs1 = gridspec.GridSpec(8, 20)
gs1.update(left=0.12, right=.94, wspace=0.12)
cm = plt.cm.get_cmap('RdYlBu')
ax1 = plt.subplot(gs1[0:7:, 0:6])
ax2 = plt.subplot(gs1[0:7, 7:13], sharey = ax1)
ax3 = plt.subplot(gs1[0:7, 14:20], sharey = ax1)
ax1.set_ylim(-2750,-2650)
ax1.plot(r_array_u, sum_dist, c = 'b', marker= '>')
ax2.plot(r_array_u, sum_dist_perp1, c = 'r', marker= '>')
ax3.plot(r_array_u, sum_dist_perp2, c = 'r', marker= '>')
第二个图由以下代码运行:
gs1 = gridspec.GridSpec(8, 20)
gs1.update(left=0.12, right=.94, wspace=0.12)
cm = plt.cm.get_cmap('RdYlBu')
ax1 = plt.subplot(gs1[0:7:, 0:6])
ax2 = plt.subplot(gs1[0:7, 7:13], sharey = ax1)
ax3 = plt.subplot(gs1[0:7, 14:20], sharey = ax1)
ax1.set_ylim(-2750,-2650)
ax1.plot(r_array, sum_dist5, c = 'b', marker= '>')
ax2.plot(r_array, sum_dist6, c = 'r', marker= '>')
ax3.plot(r_array, sum_dist7, c = 'r', marker= '>')
如何在我的代码的单次运行中,在两个单独的“窗口”(虽然我使用ubuntu)上绘制这些图?
答案 0 :(得分:2)
在绘制之前创建一个新的数字。
plt.figure()
如果你想回去,你可以这样做:
plt.figure() # figure 1
plt.plot(stuff)
plt.figure() # figure 2
plt.scatter(more_stuff_x, more_stuff_y)
# Wait, I want to add something to the first:
plt.figure(1)
plt.scatter(new_stuff)
plt.show()