PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, June 27, 2022

[FIXED] How to make the markings on y-axis more dense in a bar graph in python

 June 27, 2022     graph, python     No comments   

Issue

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

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')


Answered By - monk
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing