Is there an explicit equivalent command in Python's matplotlib for Matlab's hold on
? I'm trying to plot all my graphs on the same axes. Some graphs are generated inside a for
loop, and these are plotted separately from su
and sl
:
在Python的matplotlib中是否有一个明确的等效命令用于Matlab的控制?我要把所有的图都画在同一个坐标轴上。在for循环中生成了一些图,这些图分别从su和sl中绘制出来:
import numpy as np
import matplotlib.pyplot as plt
for i in np.arange(1,5):
z = 68 + 4 * np.random.randn(50)
zm = np.cumsum(z) / range(1,len(z)+1)
plt.plot(zm)
plt.axis([0,50,60,80])
plt.show()
n = np.arange(1,51)
su = 68 + 4 / np.sqrt(n)
sl = 68 - 4 / np.sqrt(n)
plt.plot(n,su,n,sl)
plt.axis([0,50,60,80])
plt.show()
4 个解决方案
#1
28
Just call plt.show()
at the end:
就叫plt.show()在结尾:
import numpy as np
import matplotlib.pyplot as plt
plt.axis([0,50,60,80])
for i in np.arange(1,5):
z = 68 + 4 * np.random.randn(50)
zm = np.cumsum(z) / range(1,len(z)+1)
plt.plot(zm)
n = np.arange(1,51)
su = 68 + 4 / np.sqrt(n)
sl = 68 - 4 / np.sqrt(n)
plt.plot(n,su,n,sl)
plt.show()
#2
19
You can use the following:
你可以使用以下方法:
plt.hold(True)
#3
2
The hold on
feature is switched on by default in matplotlib.pyplot
. So each time you evoke plt.plot()
before plt.show()
a drawing is added to the plot. Launching plt.plot()
after the function plt.show()
leads to redrawing the whole picture.
在matplotlib.pyplot中,默认情况下打开了对feature的保留。所以每次你唤起plt.plot()的时候,就会把画加到图中。启动plt.plot()后,函数plt.show()会导致重新绘制整个图像。
#4
0
check pyplot
docs. For completeness,
检查pyplot文档。出于完整性的考虑,
import numpy as np
import matplotlib.pyplot as plt
#evenly sampled time at 200ms intervals
t = np.arange(0., 5., 0.2)
# red dashes, blue squares and green triangles
plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
plt.show()
#1
28
Just call plt.show()
at the end:
就叫plt.show()在结尾:
import numpy as np
import matplotlib.pyplot as plt
plt.axis([0,50,60,80])
for i in np.arange(1,5):
z = 68 + 4 * np.random.randn(50)
zm = np.cumsum(z) / range(1,len(z)+1)
plt.plot(zm)
n = np.arange(1,51)
su = 68 + 4 / np.sqrt(n)
sl = 68 - 4 / np.sqrt(n)
plt.plot(n,su,n,sl)
plt.show()
#2
19
You can use the following:
你可以使用以下方法:
plt.hold(True)
#3
2
The hold on
feature is switched on by default in matplotlib.pyplot
. So each time you evoke plt.plot()
before plt.show()
a drawing is added to the plot. Launching plt.plot()
after the function plt.show()
leads to redrawing the whole picture.
在matplotlib.pyplot中,默认情况下打开了对feature的保留。所以每次你唤起plt.plot()的时候,就会把画加到图中。启动plt.plot()后,函数plt.show()会导致重新绘制整个图像。
#4
0
check pyplot
docs. For completeness,
检查pyplot文档。出于完整性的考虑,
import numpy as np
import matplotlib.pyplot as plt
#evenly sampled time at 200ms intervals
t = np.arange(0., 5., 0.2)
# red dashes, blue squares and green triangles
plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
plt.show()