Python Matplotlib-数据框中的饼图

Python Matplotlib-数据框中的饼图,python,pandas,matplotlib,Python,Pandas,Matplotlib,我从互联网上看到了一个从Matplotlib构建简单饼图的示例,但不确定如何将其嵌入我的数据集() 注意:数据集不包含任何标签,只包含值。我会这样做: my_labels = {1:'Positive',0:'Neutral',-1:'Negative'} my_colors = ['lightblue','lightsteelblue','silver'] # count the values to plot pie chart s = df.sentiment.map(my_labels)

我从互联网上看到了一个从Matplotlib构建简单饼图的示例,但不确定如何将其嵌入我的数据集()


注意:数据集不包含任何标签,只包含值。

我会这样做:

my_labels = {1:'Positive',0:'Neutral',-1:'Negative'}
my_colors = ['lightblue','lightsteelblue','silver']

# count the values to plot pie chart
s = df.sentiment.map(my_labels).value_counts()

plt.pie(s, labels=s.index, autopct='%1.1f%%', colors=my_colors)
# also
# s.plot.pie(autopct='%1.1f%%', colors=my_colors)

plt.show()
输出:

my_labels = {1:'Positive',0:'Neutral',-1:'Negative'}
my_colors = ['lightblue','lightsteelblue','silver']

# count the values to plot pie chart
s = df.sentiment.map(my_labels).value_counts()

plt.pie(s, labels=s.index, autopct='%1.1f%%', colors=my_colors)
# also
# s.plot.pie(autopct='%1.1f%%', colors=my_colors)

plt.show()