作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
pandas 绘图教程 http://pandas.pydata.org/pandas-docs/version/0.15.0/visualization.html 上的饼图示例生成下图:
使用此代码:
import matplotlib.pyplot as plt
plt.style.use('ggplot')
import numpy as np
np.random.seed(123456)
import pandas as pd
df = pd.DataFrame(3 * np.random.rand(4, 2), index=['a', 'b', 'c', 'd'], columns=['x', 'y'])
f, axes = plt.subplots(1,2, figsize=(10,5))
for ax, col in zip(axes, df.columns):
df[col].plot(kind='pie', autopct='%.2f', labels=df.index, ax=ax, title=col, fontsize=10)
ax.legend(loc=3)
plt.show()
matplotlib.pyplot.pie
的方法,但即使我仍在使用 ggplot,这个数字也不那么花哨。
f, axes = plt.subplots(1,2, figsize=(10,5))
for ax, col in zip(axes, df.columns):
patches, text, _ = ax.pie(df[col].values, autopct='%.2f')
ax.legend(patches, labels=df.index, loc='best')
最佳答案
您可以关闭图表中的标签,然后在对 legend
的调用中定义它们。 :
df[col].plot(kind='pie', autopct='%.2f', labels=['','','',''], ax=ax, title=col, fontsize=10)
ax.legend(loc=3, labels=df.index)
... labels=None ...
关于 Pandas 饼图图删除楔形上的标签文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30059862/
我是一名优秀的程序员,十分优秀!