'How to make the markings on y-axis more dense in a bar graph in python
I am plotting a bar graph in python in the following manner:
# importing package
import matplotlib.pyplot as plt
import pandas as pd
# create data
df = pd.DataFrame([['A', 10, 20, 10, 30], ['B', 20, 25, 15, 25], ['C', 12, 15, 19, 6],
['D', 10, 29, 13, 19]],
columns=['Team', 'Round 1', 'Round 2', 'Round 3', 'Round 4'])
# view data
print(df)
# plot grouped bar chart
df.plot(x='Team',
kind='bar',
stacked=False,
title='Grouped Bar Graph with dataframe')
How can I make the markings on y-axis more dense in a bar graph? That is to say, if the minimum and maximum values of y-axis is 0 and 100 respectively and the y axis is labeled at an interval of 10 units (that is we have 10 divisions) then what should we do to increase the number of divisions to say 20 or more.
Solution 1:[1]
You can specifically specify yticks
, e.g. np.arange(0, 100, 10)
. This would make the ticks go from 0 to 100 in intervals of 10
# plot grouped bar chart
df.plot(x='Team',
yticks=np.arange(0, 100, 10),
kind='bar',
stacked=False,
title='Grouped Bar Graph with dataframe')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | monk |