ошибка панели не ведет себя в журнале журнала - PullRequest
2 голосов
/ 20 июня 2019

У меня есть эти массивы

temperature = np.array([28.999795, 30.999707, 32.999471, 34.999571, 36.999753, 50.99875, 51.998767, 52.998236, 53.99675])
rate = np.array([ 8.08506648, 10.44422144, 13.77091141, 18.19601143, 24.96162138, 2538.75705877, 3517.08335312, 4981.46389811, 6818.2314983 ])
yerr = np.array([[5.12265926, 6.35525683, 8.63172001, 12.3078776, 17.48173449, 1155.0608696, 1599.30388408, 2220.70562796, 3069.64971509],[1.27615421e+01, 1.71655550e+01, 2.19724055e+01, 2.69018947e+01, 3.56424659e+01, 5.58085454e+03, 7.73609470e+03, 1.11787335e+04, 1.51522014e+04]])

Когда я отображаю ошибки как отдельные точки, их расстояния до средней точки равны ожидаемым

plt.plot(temperature, rate, marker='o', ls='none', fillstyle='none', color='r')
plt.plot(temperature, yerr[0], marker='*', ls='none', fillstyle='none', color='b' )
plt.plot(temperature, yerr[1], marker='*', ls='none', fillstyle='none', color='g' )
plt.xscale('log')
plt.yscale('log')
plt.show()

enter image description here

Однако, когда я использую встроенную функцию errorbar, я не получаю ожидаемое поведение.

plt.plot(temperature, rate, marker='o', ls='none', fillstyle='none', color='r')
plt.plot(temperature, yerr[0], marker='*', ls='none', fillstyle='none', color='b' )
plt.plot(temperature, yerr[1], marker='*', ls='none', fillstyle='none', color='g' )
plt.errorbar(temperature, rate, yerr=yerr, marker='o', ls='none', fillstyle='none', color='r' )
plt.xscale('log')
plt.yscale('log')
plt.show()

enter image description here

Кто-нибудь знает, в чем проблема?

1 Ответ

2 голосов
/ 20 июня 2019

Вы делаете фундаментальную ошибку. На первом графике у вас есть абсолютные нижние и верхние границы, а не столбцы ошибок. Столбики ошибок будут отличаться этими нижними / верхними границами от фактических rate. На втором графике, когда вы используете plt.errorbar(...), столбцы ошибок всегда определяются относительно центрального значения y (rate в вашем случае).

Таким образом, чтобы использовать аргумент yerr=yerr, фактические нижние столбцы ошибок (yerr[0]) теперь будут rate - yerr[0], тогда как фактические верхние столбцы ошибок будут yerr[1] - rate.

plt.plot(temperature, rate, marker='o', ls='none', fillstyle='none', color='r')
plt.plot(temperature, yerr[0], marker='*', ls='none', fillstyle='none', color='b' )
plt.plot(temperature, yerr[1], marker='*', ls='none', fillstyle='none', color='g' )

yerr[0] = rate - yerr[0] # Compute the actual error bar now
yerr[1] = yerr[1] - rate # Compute the actual error bar now
plt.errorbar(temperature, rate, yerr=yerr, marker='o', ls='none', fillstyle='none', color='r' )
plt.xscale('log')
plt.yscale('log')
plt.show()

enter image description here

...