调试时使用控制台命令绘制图形
plot figure using console command while debugging
我对 Python 很陌生。我正在做一个非常简单的代码,如下所示:
import numpy as np
from matplotlib.pyplot import figure
from matplotlib.pyplot import plot
from matplotlib.pyplot import grid
from matplotlib.pyplot import title
from matplotlib.pyplot import xlabel
from matplotlib.pyplot import close
from matplotlib.pyplot import ylabel
from matplotlib.pyplot import show
close("all")
figure()
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2*np.pi*t)
plot(t, s)
xlabel('time (s)')
ylabel('voltage (mV)')
title('About as simple as it gets, folks')
grid(True)
show()
我通过逐步调试,并在
执行后立即进行调试
s = 1 + np.sin(2*np.pi*t)
我尝试通过在控制台中键入命令来绘制曲线:
plot(t,s)
show()
出现的是一个图形,但是图形上没有画曲线。像这样:
我是 MATLAB 用户。 MATLAB 允许您在调试期间随时在控制台中使用命令行进行绘图,因此如果您愿意,您可以在调试期间可视化您的数据。
我可以对 Python 做同样的事情吗?谢谢
我运行你的代码,稍微改了一下。它直到 plt.show() 才显示,你 运行 那行吗?
import numpy as np
import matplotlib.pyplot as plt
plt.close("all")
plt.figure()
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2*np.pi*t)
plt.plot(t, s)
plt.xlabel('time (s)')
plt.ylabel('voltage (mV)')
plt.title('About as simple as it gets, folks')
plt.grid(True)
plt.show()
我对 Python 很陌生。我正在做一个非常简单的代码,如下所示:
import numpy as np
from matplotlib.pyplot import figure
from matplotlib.pyplot import plot
from matplotlib.pyplot import grid
from matplotlib.pyplot import title
from matplotlib.pyplot import xlabel
from matplotlib.pyplot import close
from matplotlib.pyplot import ylabel
from matplotlib.pyplot import show
close("all")
figure()
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2*np.pi*t)
plot(t, s)
xlabel('time (s)')
ylabel('voltage (mV)')
title('About as simple as it gets, folks')
grid(True)
show()
我通过逐步调试,并在
执行后立即进行调试s = 1 + np.sin(2*np.pi*t)
我尝试通过在控制台中键入命令来绘制曲线:
plot(t,s)
show()
出现的是一个图形,但是图形上没有画曲线。像这样:
我是 MATLAB 用户。 MATLAB 允许您在调试期间随时在控制台中使用命令行进行绘图,因此如果您愿意,您可以在调试期间可视化您的数据。
我可以对 Python 做同样的事情吗?谢谢
import numpy as np
import matplotlib.pyplot as plt
plt.close("all")
plt.figure()
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2*np.pi*t)
plt.plot(t, s)
plt.xlabel('time (s)')
plt.ylabel('voltage (mV)')
plt.title('About as simple as it gets, folks')
plt.grid(True)
plt.show()