Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7608381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:53:56+00:00 2026-05-31T00:53:56+00:00

I have stumbled accross the following snippet, for creating horizontal bar chart using matplotlib:

  • 0

I have stumbled accross the following snippet, for creating horizontal bar chart using matplotlib:

import matplotlib
from pylab import *

val = 3+10*rand(5)    # the bar lengths
pos = arange(5)+.5    # the bar centers on the y axis
print pos
figure(1)
barh(pos,val, align='center')
yticks(pos, ('Tom', 'Dick', 'Harry', 'Slim', 'Jim'))
xlabel('Performance')
title('horizontal bar chart using matplotlib')
grid(True)
show()

I want to modify the above script as follows:

  1. Make the plotted bars ‘less chunky’ (i.e. reduce the height of the plotted horiz bars)
  2. Plot both negative and positive numbers as horizontal bars on the same plot

any help (code snippet or links) to help me make the above modifications would be very helpful.

as an aside, if I wanted to make stacked horizontal bars (say each label had 3 stacked horizontal bars), how would I modify the code above to do plot a 3 stacked horizontal bar plot?

[[Edit]]

Could someone post two short code snippet that shows how to:

  1. Print labels on the opposite side of the horizontal bars (so that for example, the label for ‘negative’ bars appears in the 1st quarant, and the labels for ‘positive’ bars appears in the 2nd quadrant

  2. Plot multiple (say 2 or 3) horizontal bars (instead of just one). Good examples are the first two images shown here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:53:57+00:00Added an answer on May 31, 2026 at 12:53 am
    import matplotlib
    from pylab import *
    
    val = 3-6*rand(5)    # the bar lengths        # changed your data slightly
    pos = arange(5)+.5    # the bar centers on the y axis
    print pos
    figure(1)
    barh(pos,val, align='center',height=0.1)    # notice the 'height' argument
    yticks(pos, ('Tom', 'Dick', 'Harry', 'Slim', 'Jim'))
    
    gca().axvline(0,color='k',lw=3)   # poor man's zero level
    
    xlabel('Performance')
    title('horizontal bar chart using matplotlib')
    grid(True)
    show()
    

    In general, I’d suggest not using from pyplot import *. Unless you’re in the interactive mode, use the object-oriented approach:

    import matplotlib.pyplot as plt
    from numpy.random import rand
    from numpy import arange
    
    val = 3-6*rand(5)    # the bar lengths
    pos = arange(5)+.5    # the bar centers on the y axis
    print pos
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.barh(pos,val, align='center',height=0.1)
    ax.set_yticks(pos, ('Tom', 'Dick', 'Harry', 'Slim', 'Jim'))
    
    ax.axvline(0,color='k',lw=3)   # poor man's zero level
    
    ax.set_xlabel('Performance')
    ax.set_title('horizontal bar chart using matplotlib')
    ax.grid(True)
    plt.show()
    

    A good starting point for various sorts of plots is the matplotlib gallery

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have stumbled across the following issue: Using IIS6, I was trying to run
I have stumbled upon the following F77 yacc grammar: http://yaxx.cvs.sourceforge.net/viewvc/yaxx/yaxx/fortran/fortran.y?revision=1.3&view=markup . How can I
Have just started playing with ASP.NET MVC and have stumbled over the following situation.
I have recently stumbled upon a problem with selecting relationship details from a 1
I'm new to T4 but I have stumbled accross it and it looks very
I am using iframes in my page, and have stumbled across a weird issue.
I've been practicing for an upcoming programming competition and I have stumbled across a
I'm trying out ASP.NET MVC routing and have of course stumbled across a problem.
I have stumbled into several methods of looping in JavaScript, what I like the
I have stumbled in this phrase in the web: C# is probably not the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.