python - matplotlib pie怎么設(shè)置alpha
問(wèn)題描述
matplotlib.pyplot.bar有alpha這個(gè)參數(shù)但在pie里好像使用是會(huì)報(bào)錯(cuò),自帶的顏色太丑了!求大神賜教!
問(wèn)題解答
回答1:因?yàn)闆](méi)有代碼,不太清楚你的實(shí)際情況,不過(guò)下列有一些例子,是有設(shè)罝了alpha值
polar_bar_demo.py 使用 bar.set_alpha(...)
matplotlib.patches.Patch 使用 fc=(0, 0, 1, 0.5)基本上是找對(duì)象設(shè)alpha值如XXX.set_aplha()或傳參數(shù)定facecolor fc值時(shí)給四位tuple。
見(jiàn)代碼
# 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就可以了。
更多範(fàn)例見(jiàn):Wedge
相關(guān)文章:
1. matplotlib - python函數(shù)的問(wèn)題2. javascript - history.replaceState()無(wú)法改變query參數(shù)3. java - 是否類 類型指針、引用作為形參 ,函數(shù)結(jié)束不會(huì)自動(dòng)析構(gòu)類?4. angular.js - angular ng-class里面的引號(hào)問(wèn)題5. 在mac下出現(xiàn)了兩個(gè)docker環(huán)境6. mysql無(wú)法添加外鍵7. html - vue項(xiàng)目中用到了elementUI問(wèn)題8. javascript - react 中綁定事件和阻止事件冒泡9. JavaScript事件10. javascript - es6將類數(shù)組轉(zhuǎn)化成數(shù)組的問(wèn)題
