我正在尝试使用 wrap=True 包装文本,但它似乎对我不起作用。从下面的 matplotlib 运行示例:
import matplotlib.pyplot as plt
fig = plt.figure()
plt.axis([0, 10, 0, 10])
t = "This is a really long string that I'd rather have wrapped so that it"\
" doesn't go outside of the figure, but if it's long enough it will go"\
" off the top or bottom!"
plt.text(4, 1, t, ha='left', rotation=15, wrap=True)
plt.text(6, 5, t, ha='left', rotation=15, wrap=True)
plt.text(5, 5, t, ha='right', rotation=-15, wrap=True)
plt.text(5, 10, t, fontsize=18, style='oblique', ha='center',
va='top', wrap=True)
plt.text(3, …
Run Code Online (Sandbox Code Playgroud) 我正在用matplotlib馅饼作为基础创建一个量表:
import matplotlib.pyplot as plt
import math
theta = 0.2
group_size=[10,10,10,10,10,50]
mid = [18,54,90,126,162]
from textwrap import wrap
labels=['1','2','3','4','5','']
labels = [ '\n'.join(wrap(l, 9)) for l in labels ]
fig, ax = plt.subplots()
ax.axis('equal')
pie3 = ax.pie(group_size, radius=2.2, colors=['k'] ,startangle=180,counterclock=False)
my_circle=plt.Circle( (0,0), 0.4, color='white')
p=plt.gcf()
p.gca().add_artist(my_circle)
pie4 = ax.pie([10,10,10,10,10,50], radius=2, labeldistance=0.9, labels=labels,
startangle=180,rotatelabels =True,counterclock=False)
plt.setp(pie4[1], rotation_mode="anchor", ha="center", va="center")
for tx in pie4[1]:
font = tx.get_fontsize()
tx.set_fontsize(12)
rot = tx.get_rotation()
tx.set_rotation(rot+90+(1-rot//180)*180)
for pie_wedge in pie3[0]:
pie_wedge.set_edgecolor('white')
for pie_wedge in pie4[0]:
pie_wedge.set_edgecolor('white') …
Run Code Online (Sandbox Code Playgroud) 使用 matplot 创建一个带有以下代码的小仪表:
group_size=[10,10,10,10,10,50]
labels=['AAAA','BBBB','CCCC','DDDD','EEEE','']
fig, ax = plt.subplots()
ax.axis('equal')
pie = ax.pie(group_size, radius=2.2, colors=['k'] ,startangle=180,counterclock=False)
pie2 = ax.pie([10,10,10,10,10,50], radius=2, labeldistance=0.7, labels=labels, rotatelabels = 270,
startangle=180,counterclock=False)
plt.show()
Run Code Online (Sandbox Code Playgroud)
我试图让标签水平移动并像这样与每个楔形的中点对齐(但带有楔形内的文本):
使用rotatelabel=True,我得到以下信息:
关于如何实现图形标签水平旋转的任何想法?