python - 如何在 Jupyter Python 中去除饼图之前的文本
问题描述
我正在尝试使用此 CSV 文件中的数据制作饼图。问题是它可以工作,但它在饼图之前显示文本,我想摆脱它。
另外,如何缩放条形图使其完全适合工作簿?
#imports for pandas and numpy
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import*
from collections import OrderedDict
from collections import Counter
#Importing the file where I get the data from
df = pd.read_csv('file.csv',delimiter=',', skipinitialspace = True)
df['artist genre'].value_counts()
genreArray = np.array(df['artist genre'])
keys = Counter(genreArray).keys()
values = Counter(genreArray).values()
#counts =Counter(genreArray)
plt.pie([float(v) for v in values], labels=[k for k in keys],
autopct=None,frame=True)
结果:
([<matplotlib.patches.Wedge at 0x28d57bec160>,
<matplotlib.patches.Wedge at 0x28d57bec6a0>,
<matplotlib.patches.Wedge at 0x28d57becbe0>,
<matplotlib.patches.Wedge at 0x28d57bf5160>,
<matplotlib.patches.Wedge at 0x28d57bf56a0>,
<matplotlib.patches.Wedge at 0x28d57bf5be0>,
<matplotlib.patches.Wedge at 0x28d57bfc160>,
<matplotlib.patches.Wedge at 0x28d57bfc6a0>,
<matplotlib.patches.Wedge at 0x28d57bfcc88>,
<matplotlib.patches.Wedge at 0x28d57c09208>,
<matplotlib.patches.Wedge at 0x28d5796acc0>,
<matplotlib.patches.Wedge at 0x28d57c09c50>,
<matplotlib.patches.Wedge at 0x28d57c101d0>,
<matplotlib.patches.Wedge at 0x28d57c10710>],
[Text(0.801866,0.753002,'Pop'),
Text(-0.646564,0.889919,'Hip Hop'),
Text(-1.08052,-0.206119,'Electronic Dance Music'),
Text(-0.753002,-0.801865,'Latin Pop'),
Text(-0.273559,-1.06544,'R&B'),
Text(0.172078,-1.08646,'Pop Rock'),
Text(0.339919,-1.04616,'Electronic Music'),
Text(0.468357,-0.99531,'Deep House'),
Text(0.701166,-0.847565,'Reggaeton'),
Text(0.946816,-0.559946,'Progressive House'),
Text(1.04616,-0.339919,'Dance Pop'),
Text(1.08052,-0.20612,'Electropop'),
Text(1.09512,-0.103519,'Country'),
Text(1.09946,-0.0345519,'Indie Pop')])
解决方案
plt.pie(...);
您可以在通话结束时添加分号。
推荐阅读
- google-sheets - 如何按包含数字作为文本的列对查询进行排序
- javascript - 在删除这些节点后存储节点的 Javascript 持久变量
- ios - iOS - UIAlertController 操作未触发处理程序
- javascript - TypeError:AWS.Chime 不是 vuejs 的构造函数
- typescript - TypeScript:TS2339 错误——“对象”类型上不存在属性
- xamarin - Xamarin 添加和删除内容
- html - 如何删除导航栏上方的空白?
- pharo - Pharo 中的 at ("@") 运算符是什么?
- javascript - 访问javascript文件中的服务器值?
- nopcommerce - NopCommerce google bot 和 facebook 抓取通过登录页面重定向