Python相当于Matlab中的“hold on” [英] Python equivalent to 'hold on' in Matlab
本文介绍了Python相当于Matlab中的“hold on”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Matlab的上保留
的Python matplotlib中是否存在明确的等价命令?我试图在同一轴上绘制所有的图形。一些图是在中为循环生成的,它们分别从
su
和 sl
:
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
:
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()
推荐答案
只需调用 plt.show()
Just call plt.show()
at the end:
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()
这篇关于Python相当于Matlab中的“hold on”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文