Python相当于Matlab中的'hold on' [英] Python equivalent to 'hold on' in Matlab
本文介绍了Python相当于Matlab中的'hold on'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Python 的 matplotlib 中是否有明确的等效命令用于 Matlab 的 hold on
?我试图在相同的轴上绘制我的所有图形.一些图是在 for
循环内生成的,这些图与 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()
即可:
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屋!
查看全文