Hi,
I am having a question regarding a pie-chart labels alignment. I'd like to
have labels outside the pie-chart and centered to each wedge. According to
the documentation page, "labeldistance" parameter enables to place labels
outside the pie-chart, and "ha" & "va" parameters supposed to center.
However, these two options (ha & va) seems not working on Matplotlib
v2.1.0+. 1) With this example (pls see below), you can see that "car" label
is not centered properly, it is a bit off the center.
import matplotlib.pyplot as plt
figure = plt.figure()
axes = figure.add_subplot(111)
axes.set_aspect(1) # circular pie
y = [1,2,3, 4,8,16,18]
label = ['car','domino', 'romancical','testing1', 'thisisthelonglabel',
'fffffffffffffffffffffffffffffffffffffffffff', 'as']
wedges, texts = plt.pie(y,
radius=1.2,
labels=label,
labeldistance=1.0,
rotatelabels =True,
startangle = 10,
wedgeprops = {"linewidth": 0.7,
"edgecolor": "white"},
textprops = dict(ha="center",
va="center")) # doesn't work
plt.show()
<http://matplotlib.1069221.n5.nabble.com/file/t5207/pic1.png>
I added the following lines to force labels to be centered, which works but
disabled a "labeldistance" parameter. So all my centered correctly, as I
want labels are overlapping with the pie-chart circle now.
wedges, texts = plt.pie(y,
radius=1.2,
labels=label,
labeldistance=1.0,
rotatelabels =True,
startangle = 10,
wedgeprops = {"linewidth": 0.7,
"edgecolor": "white"},
textprops = dict(va="center"))
for t in texts:
#t.set_horizontalalignment("center")
t.set_verticalalignment("center")
plt.show()
<http://matplotlib.1069221.n5.nabble.com/file/t5207/pic2.jpg>
It seems that "va" option works perfectly for users of Matplotlib v 3.0.2,
but it doesnt on v 2.2.2
Could you please advice if there is a solution for keeping "labeldistance"
while using .set_horizontalalignment("center") ?
S: Pls. note the same question is posted on stackoverflow.com:
Thanks
ยทยทยท
--
Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html