python饼状图顺时针_Python matplotlib顺时针饼图
我正在研究Python及其matplotlib庫,如何創建以下圖表,以便第一個切片從頂部開始并向右(順時針)而不是向左(逆時針)移動:
代碼:import matplotlib.pyplot as plt
import re
import math
# The slices will be ordered and plotted counter-clockwise if startangle=90.
sizes = [175, 50, 25, 50]
total = sum(sizes)
print('TOTAL:')
print(total)
print('')
percentages = list(map(lambda x: str((x/(total * 1.00)) * 100) + '%', sizes))
print('PERCENTAGES:')
print(percentages)
backToFloat = list(map(lambda x: float(re.sub("%$", "", x)), percentages))
print('')
print('PERCENTAGES BACK TO FLOAT:')
print(backToFloat)
print('')
print('SUM OF PERCENTAGES')
print(str(sum(backToFloat)))
print('')
labels = percentages
colors = ['blue', 'red', 'green', 'orange']
patches, texts = plt.pie(sizes, colors=colors, startangle=-270)
plt.legend(patches, labels, loc="best")
# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')
plt.tight_layout()
plt.show()
總結
以上是生活随笔為你收集整理的python饼状图顺时针_Python matplotlib顺时针饼图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java勇者大冒险_勇者大冒险 第一集
- 下一篇: java opennlp_OpenNLP