[英]Matplotlib - error bars not centered on points
我知道它在matplotlib之前一直是個問題 - 但它應該已經修復了,對吧?
當我執行。 我的散點圖示例代碼:
%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
import numpy as np
plt.xlabel(r'$Label \, in \, Latex$')
plt.ylabel(r'$Label \, in \, Latex$')
plt.title(r'$Title \, in \, Latex$')
#plt.text(1, 15, r'$Latex \, Example \, Text$')
x=[1, 2, 3, 4]
y=[1, 4, 9, 16]
plt.axis([0, 6, 0, 20])
plt.errorbar(x, y, yerr=1, fmt='.k', capsize=3)
plt.savefig('foo.pdf', bbox_inches="tight")
誤差線不以點為中心。 我正在使用matplotlib 3.02 - Anaconda不知何故不承認有3.03。
我找到了以下解決方法:為錯誤欄指定linewidth=1
使它們居中。 我嘗試了幾個值,低於1.5的任何值都集中在一起,但是任何高於1.5(包括)的值都會使它偏離中心。 我不知道原因。 它可能與dpi
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
import numpy as np
plt.xlabel(r'$Label \, in \, Latex$')
plt.ylabel(r'$Label \, in \, Latex$')
plt.title(r'$Title \, in \, Latex$')
#plt.text(1, 15, r'$Latex \, Example \, Text$')
x=[1, 2, 3, 4]
y=[1, 4, 9, 16]
plt.axis([0, 6, 0, 20])
plt.errorbar(x, y, yerr=1, lw=1, fmt='.k', capsize=3)
保存為.svg
解決了我的問題。 使用jupyter筆記本時,繪圖顯示為非居中的誤差條,但保存正確。
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
import numpy as np
plt.xlabel(r'$Label \, in \, Latex$')
plt.ylabel(r'$Label \, in \, Latex$')
plt.title(r'$Title \, in \, Latex$')
#plt.text(1, 15, r'$Latex \, Example \, Text$')
x=[1, 2, 3, 4]
y=[1, 4, 9, 16]
plt.axis([0, 6, 0, 20])
plt.errorbar(x, y, yerr=1, lw=2, fmt='o', capsize=3)
plt.savefig('TEST.svg', bbox_inches='tight', format='svg')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.