我使用包含錯誤欄(圍繞欄頂對稱)的熊貓barplot繪製數據,並且我想修改此圖中單個錯誤欄的範圍,以便它只顯示一半。我怎樣才能做到這一點?在pandas barplot中修改一個錯誤欄範圍
這裏有一個具體的例子:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
bars = pd.DataFrame(np.random.randn(2,2), index=['a','b'], columns=['c','d'])
errs = pd.DataFrame(np.random.randn(2,2), index=['a','b'], columns=['c','d'])
ax = bars.plot.barh(color=['r','g'],xerr=errs)
它產生這樣一個情節:
我想事後訪問和修改的errorbar程度索引a
和列d
,以便它只顯示它的前半部分,即段[bar_top-err, bar_top]
而不是[bar_top-err, bar_top+err]
。我試圖檢索以下matplotlib對象:
plt.getp(ax.get_children()[1],'paths')[0]
,如果我沒有記錯,是一個Bbox
,並介紹合適的對象,但我不能去修改它在我的陰謀。任何想法如何做到這一點?
'型(plt.getp(斧頭。 get_children()[1],'paths')[0])'告訴我它實際上是一個'matplotlib.path.Path'。 – whrrgarbl
當然,它實際上是'matplotlib.transforms.Bbox'類型的'plt.getp(ax.get_children()[1],'paths')[0] .get_extents()'。但具體而言,這並不能幫助我找出解決方案...... – fseyrl