Python 在matplotlib中以特定角度使用楔块上的分形绘制饼图
我正在使用matplotlib使用以下代码绘制piechart:Python 在matplotlib中以特定角度使用楔块上的分形绘制饼图,python,matplotlib,pie-chart,wedge,Python,Matplotlib,Pie Chart,Wedge,我正在使用matplotlib使用以下代码绘制piechart: ax = axes([0.1, 0.1, 0.6, 0.6]) labels = 'Twice Daily', 'Daily', '3-4 times per week', 'Once per week','Occasionally' fracs = [20,50,10,10,10] explode=(0, 0, 0, 0,0.1) patches, texts, autotexts = ax.pie(fracs, labels
ax = axes([0.1, 0.1, 0.6, 0.6])
labels = 'Twice Daily', 'Daily', '3-4 times per week', 'Once per week','Occasionally'
fracs = [20,50,10,10,10]
explode=(0, 0, 0, 0,0.1)
patches, texts, autotexts = ax.pie(fracs, labels=labels, explode = explode,
autopct='%1.1f%%', shadow =True)
proptease = fm.FontProperties()
proptease.set_size('xx-small')
setp(autotexts, fontproperties=proptease)
setp(texts, fontproperties=proptease)
rcParams['legend.fontsize'] = 7.0
savefig("pie1")
这将生成以下图表。
然而,我想以顶部的第一个楔子开始饼图,我能找到的唯一解决方案是使用
但是,在如下所示的情况下
from pylab import *
from matplotlib import font_manager as fm
from matplotlib.transforms import Affine2D
from matplotlib.patches import Circle, Wedge, Polygon
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111)
labels = 'Twice Daily', 'Daily', '3-4 times per week', 'Once per week','Occasionally'
fracs = [20,50,10,10,10]
wedges, plt_labels = ax.pie(fracs, labels=labels)
ax.axis('equal')
starting_angle = 90
rotation = Affine2D().rotate(np.radians(starting_angle))
for wedge, label in zip(wedges, plt_labels):
label.set_position(rotation.transform(label.get_position()))
if label._x > 0:
label.set_horizontalalignment('left')
else:
label.set_horizontalalignment('right')
wedge._path = wedge._path.transformed(rotation)
plt.savefig("pie2")
这将生成以下饼图
但是,这不会像前面的饼图那样在楔块上打印分形。我尝试了一些不同的方法,但我无法保持压裂效果。如何在中午启动第一个楔子,并在楔子上显示裂缝???通常我不建议更改工具的来源,但在外部修复此问题非常困难,在内部也很容易。所以,如果你现在需要这个来工作,我会这么做(tm),有时你也需要 在文件
matplotlib/axes.py
中,将饼图函数的声明更改为
def pie(self, x, explode=None, labels=None, colors=None,
autopct=None, pctdistance=0.6, shadow=False,
labeldistance=1.1, start_angle=None):
i、 e.只需在参数末尾添加start\u angle=None
然后加上用“#加法”括起来的五行
如果“开始角度”为“无”,则不会发生任何情况,但如果“开始角度”有一个值,则第一个切片(在本例中为20%)的中心位置。比如说,
patches, texts, autotexts = ax.pie(fracs, labels=labels, explode = explode,
autopct='%1.1f%%', shadow =True, start_angle=0.75*pi)
产生
请注意,一般情况下,您应该避免这样做,我的意思是修补源代码,但在过去的一些时候,我一直在截止日期,只是想现在(tm)的东西,所以你去
patches, texts, autotexts = ax.pie(fracs, labels=labels, explode = explode,
autopct='%1.1f%%', shadow =True, start_angle=0.75*pi)