如何在Jupyter Python中去掉饼图之前的文本

2024-10-08 19:30:51 发布

您现在位置: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')])

This is the bar chart that is returned then


Tags: textfromimportdfformatplotlibascounter

热门问题