我复制了以下示例代码并进行了轻微更改。我想将分数以一定角度旋转。我实现了我的目标,但我的问题是是否有更简单的方法可以旋转分数:
import matplotlib.pyplot as plt
import matplotlib
# Data to plot
labels = 'Python', 'C++', 'Ruby', 'Java'
sizes = [215, 130, 245, 210]
colors = ['gold', 'yellowgreen', 'lightcoral', 'lightskyblue']
explode = (0.1, 0, 0, 0) # explode 1st slice
# Plot
pie_properties = plt.pie(sizes, labels=labels, colors=colors,
autopct='%1.1f%%', shadow=False, startangle=140, pctdistance=0.8, radius = 0.5)
# Rotate fractions
# [0] = wedges, [1] = labels, [2] = fractions
fraction_text_list = pie_properties[2]
for text in fraction_text_list:
text.set_rotation(315)
plt.axis('equal')
plt.show()
有没有可能改进这个问题?
plt.pie(sizes, labels=labels, ..., textprops={'rotation': 315}, ...)
。 - Paul H