如何使用matplotlib打印gnuplot的“with pulses”样式?

2024-09-28 18:56:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用python/pandas/matplotlib创建一个类似下面的图。上面的剪辑没问题,但我还没能像下面的剪辑那样得到一个情节。我可以在gnuplot中这样做,在gnuplot中等效的打印样式是“with pulses”。使用matplotlib可以吗?如果不能使用matplotlib,是否还有其他python图形包可以工作?在

The gnuplot style for the lower clip is 'with impulses'


Tags: 图形pandasmatplotlib剪辑with样式情节gnuplot
2条回答

下面是一个使用vlines的示例,正如@importanceofbeingrenes建议的那样,这引发了另一个问题。一种解决方案比另一种更好吗?在某种程度上更有效还是更好?在

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0.1, 6*np.pi, 50)
plt.vlines(x, 0, np.cos(x)+1, color='g')
plt.vlines(x, 0, -np.sin(x)-1, color='r')
plt.show()

enter image description here

创建这种绘图最简单的方法是使用^{}。 可以找到一个例子here。在

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0.1, 6*np.pi, 50)
plt.stem(x, np.cos(x)+1, linefmt='g-', markerfmt=' ')
plt.stem(x, -np.sin(x)-1, linefmt='r-', markerfmt=' ', basefmt="gray")

plt.show()

enter image description here

另一个选择是使用^{}。在

相关问题 更多 >