如何将连接点的曲线改为垂直方向?

时间:2015-05-15 13:01:08

标签: python matplotlib

以下代码将通过连接点创建绘图。

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 5, 0.1);
y = np.sin(x)
plt.plot(x, y)
plt.show()

enter image description here

如何将绘图更改为竖条而不是连接点?即,更改为以下示例的绘图类型:

enter image description here

感谢。

1 个答案:

答案 0 :(得分:2)

使用plt.bar

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 5, 0.1);
y = np.sin(x)
plt.bar(x, y, width=0.08,edgecolor='None',color='k',align='center')
plt.show()

enter image description here