简体   繁体   中英

show values on bars in bar charts

I have dataframe with column(C_NC) containing two values namely C and NC. I plotted frequency of C and NC values with

df['C_NC'].value_counts().plot(kind='bar')

在此处输入图像描述

Though this graph is nice, I also want to have exact frequency number on each bar in bar chart. I am quite new to Data visualization with Pandas Dataframe. Is there a way to do this with pandas dataframe?

Use:

s=df['C_NC'].value_counts()
s.plot(kind='bar',yticks=s)

Example

as you can see here is the same problem:

import numpy as np
import matplotlib.pyplot as plt
s1=pd.Series(np.random.randint(0,2,300))
s=s1.value_counts()
print(s)


1    156
0    144
dtype: int64

s1.value_counts().plot(kind='bar')

在此处输入图像描述


we can now show the exact values

s.plot(kind='bar',yticks=s)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM