2015-04-16 120 views

回答

2

我不認爲有什麼辦法可以使用linewidth屬性來做到這一點,因爲線的筆畫總是對稱於線的中心。

稍微哈克變通是使用表示欄matplotlib.patches.Rectangle對象的set_clip_path()方法:

from matplotlib import pyplot as plt 

fig, ax = plt.subplots(1, 1) 

ax.hold(True) 

patches = ax.bar([1],[1], lw = 20., facecolor = 'w', edgecolor= 'red') 
ax.plot([0,2],[0,0], 'k') 
ax.plot([0,2],[1,1], 'k') 

ax.set_xlim(0.8,2) 
ax.set_ylim(-0.2,1.2) 

# get the patch object representing the bar 
bar = patches[0] 

# set the clipping path of the bar patch to be the same as its path. this trims 
# off the parts of the bar edge that fall outside of its outer bounding 
# rectangle 
bar.set_clip_path(bar.get_path(), bar.get_transform()) 

enter image description here

See here爲matplotlib文檔中的另一個例子。

相關問題