【发布时间】:2019-03-06 09:46:03
【问题描述】:
我尝试在 Ubuntu 18.10 上使用 Python 3 Matplotlib v2.2.2-4build1 绘制饼图。一切似乎都很好,除了标签——它们不见了。尝试根据官方文档添加(https://matplotlib.org/api/_as_gen/matplotlib.pyplot.pie.html),尝试使用网络上的示例(https://pythonspot.com/matplotlib-pie-chart/) - 结果相同,没有标签。
这是我的代码的简化版本:
import numpy as np
import matplotlib.pyplot as plt
import sys
headers = ['a', 'b', 'c', 'd', 'e']
values = [5, 4, 3, 2, 1]
sum = sum(values)
labels = []
for v in values:
labels.append('{:.1f}%'.format(100 * v / sum))
fig, ax = plt.subplots(figsize=(6, 3), subplot_kw=dict(aspect="equal"))
wedges, texts = ax.pie(values, labels=labels, textprops=dict(color="w"))
plt.show()
这是我看到的 - 没有标签:
尝试使用元组而不是列表 - 同样的事情。
有人可以帮我吗?
【问题讨论】:
标签: python matplotlib plot