2012-11-23 54 views
3

有沒有辦法在使用PatchCollection時填充圓圈?我繪製了一個圓圈,我嘗試將facecolor設置爲「無」,但它覆蓋了繪製在其上的等值線圖。我希望看到輪廓的輪廓在其後面保持可見。Python:Matplotlib修補程序和輪廓圖

使用mplstereonet-0.2第三方軟件繪製立體圖。這裏就是圖像繪製腳本的一部分:

hold(True) 



fig, ax = plt.subplots(subplot_kw = dict(projection = 'stereonet')) # Schmidt by default 

cax = ax.density_contourf(strike, dip, measurement = 'poles') 

ax.pole(strike, dip, 'k^', markersize = 3) 
ax.grid(True) 


patches = [] 
circle = Circle((0, 0), 0.5, facecolor = 'none', fill = False) 
patches.append(circle) 
p = PatchCollection(patches) 
ax.add_collection(p) 

cbar = fig.colorbar(cax, cmap = cm) 
cbar.set_clim(0, 25) 

enter image description here

回答

3

我解決了這個問題,但感謝你給任何人,是可能尋找到這一點。

解決辦法:

p = PatchCollection(patches, match_original = True) 

這將讓這個輪廓看的形狀後面。

enter image description here

+2

我正要回應。我的意見是,如果你只繪製1圈,避免整個PatchCollection並直接添加它: ax.add_artist(circle) –

+1

不錯。我打算建議使用'ax.add_patch(circle)',它工作正常(如果你只有一個補丁就不需要使用PatchCollection)。儘管如此,你應該真的在你的問題中提供了一個最小的工作例子。 – jorgeca

+2

只是FYI,當創建'PatchCollection'(或者使用'p.set_facecolor')時,你也可以指定'facecolor ='none''。在製作集合時默認不匹配原始補丁的原因是,集合通常用於加速繪製一堆幾乎完全相同的藝術家,或者將某些屬性(如facecolor)映射到另一個標量(例如, z')。 (另一方面,我甚至不知道'match_original'選項存在,這很方便!)正如其他人所提到的,對於一個圓圈,直接添加它更容易。祝你好運! –