python - matplotlib pie怎么設置alpha
問題描述
matplotlib.pyplot.bar有alpha這個參數但在pie里好像使用是會報錯,自帶的顏色太丑了!求大神賜教!
問題解答
回答1:因為沒有代碼,不太清楚你的實際情況,不過下列有一些例子,是有設罝了alpha值
polar_bar_demo.py 使用 bar.set_alpha(...)
matplotlib.patches.Patch 使用 fc=(0, 0, 1, 0.5)基本上是找對象設alpha值如XXX.set_aplha()或傳參數定facecolor fc值時給四位tuple。
見代碼
# Pie chart, where the slices will be ordered and plotted counter-clockwise:labels = ’Frogs’, ’Hogs’, ’Dogs’, ’Logs’sizes = [15, 30, 45, 10]explode = (0, 0.1, 0, 0) # only 'explode' the 2nd slice (i.e. ’Hogs’)fig1, ax1 = plt.subplots()patches, texts, autotexts = ax1.pie(sizes, explode=explode, labels=labels, autopct=’%1.1f%%’,shadow=True, startangle=90)for i, p in enumerate(patches): p.set_alpha(0.25*i)plt.show()
patches/wedges set_alpha就可以了。
更多範例見:Wedge
相關文章:
1. html5 - 有可以一次性把所有 css外部樣式轉為html標簽內style=" "的方法嗎?2. javascript - 求解答:實例對象調用constructor,此時constructor內的this的指向?3. javascript - 如何將一個div始終固定在某個位置;無論屏幕和分辨率怎么變化;div位置始終不變4. python - 如何判斷爬蟲已經成功登陸?5. javascript - 原生canvas中如何獲取到觸摸事件的canvas內坐標?6. javascript - 這不是對象字面量函數嗎?為什么要new初始化?7. javascript - vscode alt+shift+f 格式化js代碼,通不過eslint的代碼風格檢查怎么辦。。。8. javascript - 有什么比較好的網頁版shell前端組件?9. javascript - [js]為什么畫布里不出現圖片呢?在線等10. html - vue項目中用到了elementUI問題
