2

I am trying to plot bar chart in python .. but i want to be y axis in integer and i want to print every data point from 1 to 20 on y axis. e.g 1 ,2 ,3 ,4 5,6 ,7 8,9,10,11,12,131,4,15,16,17,18,19,20 anyone help

libraries

import numpy as np
import matplotlib.pyplot as plt
 
# set width of bars
barWidth = 0.25
 
# set heights of bars
bars1 = [12, 4, 1, 8, 20,16]
bars2 = [2, 6, 16, 6, 10,18]

#bars3 = [29, 3, 24, 25, 17]
 
# Set position of bar on X axis
r1 = np.arange(len(bars1))
r2 = [x + barWidth for x in r1]
#r3 = [x + barWidth for x in r2]
 
# Make the plot
plt.bar(r1, bars1,  width=barWidth, edgecolor='white',label='var1')
plt.bar(r2, bars2, width=barWidth, edgecolor='white', label='var2') 
#plt.bar(r3, bars3, color='#2d7f5e', width=barWidth, edgecolor='white', label='var3')
 
# Add xticks on the middle of the group bars

plt.xticks([r + barWidth for r in range(len(bars1))], ['87%', '10%', '45%', '80%', '25%', '16%'])
 
# Create legend & Show graphic
plt.legend()
plt.show()

enter image description here

user12
  • 761
  • 8
  • 24

1 Answers1

0

With this plt.yticks(np.arange(1, 20+1, 1.0))

For more elaborate answer: Changing the "tick frequency" on x or y axis in matplotlib?