Python - 没有绘图的错误栏

时间:2015-10-14 13:53:34

标签: python matplotlib

我的代码制作了两个图,但我想只为Eobl绘图。 E必须只有点和误差线,没有线连接点。我怎么能这样做?

import numpy as np
import pylab as plt

fig = plt.figure()
ax = plt.axes(polar=True)

E =  np.array([3.21,3.03,2.69,2.13,1.58,0.98,0.52,0.14,0.03,0.00,0.20,0.63,1.25,2.00,2.60,2.98,3.27,3.32,3.29,3.03,2.71,2.15,1.58,
    0.98,0.58,0.12,0.01,0.00,0.15,0.58,1.13,1.78,2.47,2.92,3.17,3.29])

Eobl =  np.array([3.25,3.15,2.87,2.44,1.91,1.34,0.81,0.38,0.10,0.00,0.10,0.38,0.81,1.34,1.91,2.44,2.87,3.15,3.25,3.15,2.87,2.44,1.91,
1.34,0.81,0.38,0.10,0.00,0.10,0.38,0.81,1.34,1.91,2.44,2.87,3.15])

theta = 2*np.pi/360 * np.array(list(range(90, 450, 10)))

ax.plot(theta, E, "ro", color = '#000000')
ax.errorbar(theta, E, yerr=0.09, xerr=0.023, capsize=0, color = '#0000ff')

ax.plot(theta, Eobl, "ro")
ax.errorbar(theta, Eobl, color = '#ff0000')

plt.show()

1 个答案:

答案 0 :(得分:1)

fmt参数控制连接点的格式。您可以使用参数'none'禁用它,即

ax.errorbar(... fmt='none')

所以,对于你的情况:

ax.errorbar(theta, E, yerr=0.09, xerr=0.023, capsize=0, color='#0000ff', fmt='none')