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 973215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:14:46+00:00 2026-05-16T03:14:46+00:00

I want to keep the width of the bars the same no matter the

  • 0

I want to keep the width of the bars the same no matter the number of bars compared is high or low.
I am using Matplotlib stacked bar chart.
the width of the bars is relative to the number of the bars.
Here is my sample code.

How can I make the width the same no matter the number of bars I compare from 1 to 10

import numpy as np
import matplotlib.pyplot as plt




N =1  
ind = np.arange(N)    # the x locations for the groups
width = 0.35       # the width of the bars: can also be len(x) sequence




design = []
arch = []
code = []

fig = plt.figure()



b   = [70]
a= np.array([73])
c = [66]




p1 = plt.bar(ind, a,width, color='#263F6A')
p2 = plt.bar(ind, b, width, color='#3F9AC9', bottom=a)
p3 = plt.bar(ind, c, width, color='#76787A', bottom=a+b)


plt.ylabel('Scores')
plt.title('CQI Index')


plt.xticks(ind+width/2., ('P1'))#dynamic - fed

plt.yticks(np.arange(0,300,15))


plt.legend( (p1[0], p2[0], p3[0]), ('A','B','C') )
plt.grid(True)

plt.show()

Thank you

  • 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-16T03:14:47+00:00Added an answer on May 16, 2026 at 3:14 am

    The width of the bars doesn’t change, the scale of your image changes. If you want the scale to stay the same you have to manually specify what range you want to show, whether your plot is 10×10, 100×100, or 1,000,000,000 x 10

    Edit:

    If I understand correctly, what you want is something like this:

    Graph 1 – 2 bars:

    10
    +---------------------------+
    |                           |
    |                           |
    |                           |
    |                           |
    |                           |
    |       4_                  |
    |       | |                 |
    |  2_   | |                 |
    |  | |  | |                 |
    |  | |  | |                 |
    +---------------------------+ 10
    

    Graph 2 – add 2 more bars

    10
    +---------------------------+
    |                           |
    |                           |
    |                 7_        |
    |                 | |       |
    |                 | |       |
    |       4_        | |       |
    |       | |  3_   | |       |
    |  2_   | |  | |  | |       |
    |  | |  | |  | |  | |       |
    |  | |  | |  | |  | |       |
    +---------------------------+ 10
    

    Where the apparent width of the bars hasn’t changed from Graph 1 to Graph 2. If this is what you want to do then you’ll need to set the scale of your plot

    You can do that with

    import matplotlib
    matplotlib.use('GTKAgg')
    
    import matplotlib.pyplot as plt
    import gobject
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    
    def draw1():
        plt.bar(0,2)
        plt.bar(2,4)
        ax.set_xlim((0,10))
        ax.set_ylim((0,10))
        fig.canvas.draw()
        return False
    
    def draw2():
        plt.bar(4,3)
        plt.bar(6,7)
    
        ax.set_xlim((0,10))
        ax.set_ylim((0,10))
        fig.canvas.draw()
        return False
    
    draw1()
    gobject.timeout_add(1000, draw2)
    plt.show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've started using svn with Versions.app locally, as I want to keep trace of
I want to keep tabs on the number of concurrent users of my application.
I want to keep the field and the icon (question mark) at the same
I want to keep the element the same size AND alternate text within the
I want to keep copies of every IMG width and height in originalWidth and
I want to get the current width of an html form using javascript. I'm
i want to keep my app in sync with the Server. The communication between
If I want to keep an xml file updated with all the images that
I am parsing a HTML document with XPATH and I want to keep all
I want to replace duplicate elements from a vector with 0, and keep only

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.