0

Here's my issue : i have a dataframe that reads from a csv like this

DAY;FILE_TYPE
20210101;csv
20210102;xml
20210102;xml
20210102;xml
20210103;doc

i want to plot the count of evry type of file except the 'doc' file ;here is my code that reads from the file calculates counts in a crosstab and creates the chart:

df=pd.read_csv(r"/applis/prisme/informatica/version/scripts/test2.csv",sep=';')
tab=pd.crosstab(df['DAY'],df['FILE_TYPE'])
tab=tab.drop(['doc'],errors='ignore',axis=1)
fig=plt.figure()
tab.plot(kind='bar',figsize=(16,15))
plt.yticks(np.arange(0, 2, 1))

and this is my chart i get

enter image description here

Now my issue is in the plot: supposingly that i sized the yticks at maximum '2' what i wanna do is when the bar exceed from that value , i want it to be blocked at that value and a label bar appears on it indicating it's real value like this.

enter image description here

PS: i'm using python 2.7 (bar_label doesn'work for me)

Mr. T
  • 11,960
  • 10
  • 32
  • 54
M.Bennani
  • 31
  • 1
  • 5
  • 1
    you can `clip` the data or use a [broken axis](https://stackoverflow.com/questions/5656798/python-matplotlib-is-there-a-way-to-make-a-discontinuous-axis), or simply set a limit on the y-axis span – mozway Feb 03 '22 at 09:59
  • i used np.clip(pd.crosstab(df['DAY'],df['FILE_TYPE']),0,2) , and it is working fine to block my bar , but i'm still missing the bar_label that appears when my value exceed from the max value('2') – M.Bennani Feb 03 '22 at 11:04
  • 1
    There is no automagic method ;) You have to add labels manually (using a loop). – mozway Feb 03 '22 at 11:05

0 Answers0