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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:39:38+00:00 2026-06-17T10:39:38+00:00

I have the following datasets .I need to plot barchats for say 1,2 or

  • 0

I have the following datasets .I need to plot barchats for say 1,2 or all of them.When I plot the chart for a single data item (eg: xdata=[0] and ydata=[1000], xlabels=['first'] , the bar is sclaed to occupy the whole plot area.How do I restrict the barwidth to be say 0.45?

ydata=[1000,250,3000,500,3200,4000,2000]
xlabels=['first','sec','third','fourth','fifth','sixth','seventh']

barwidth = 0.45

import matplotlib.pyplot as plt

def create_bar_plot(entries):
    assert entries > 0    
    xdata = range(entries)
    xlabels=xlabels[:entries]
    xdata=xdata[:entries]
    ydata=ydata[:entries]        
    figure = plt.figure(figsize = (12,6), facecolor = "white")
    ax = figure.add_subplot(1,1,1)
    plt.grid(True)
    if xdata and ydata:
        ax.bar(xdata, ydata, width=barwidth,align='center',color='blue')
        ax.set_xlabel('categories',color='black')
        ax.set_ylabel('duration in  minutes',color='black')
        ax.set_title('duration plot created ')
        ax.set_xticks(xdata)
        ax.set_xticklabels(xlabels)
        figure.autofmt_xdate(rotation=30)
        plt.show()

When I tried

create_bar_plot(5)

I got this figure
https://i.stack.imgur.com/nhHEM.jpg

But when I called

create_bar_plot(1)

I get this fat bar

https://i.stack.imgur.com/e0IJi.jpg

So, how do I make the plot show each bar with fixed width? It seems the width=barwidth in bar() doesn’t work as I expected it would.. Very likely I am missing something..

Please help

  • 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-06-17T10:39:40+00:00Added an answer on June 17, 2026 at 10:39 am

    They are actually the same bar width, it’s just your x-axis scale that is different. See:

    >>> create_bar_plot(5)
    >>> plt.gca().get_xbound()
    (-1.0, 5.0)
    >>> create_bar_plot(1)
    >>> plt.gca().get_xbound()
    (-0.30000000000000004, 0.30000000000000004)
    >>> ax = plt.gca()
    >>> ax.set_xbound(-1.0 ,5.0)
    >>> plt.show()
    

    1

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

Sidebar

Related Questions

I have the following data that basically I only need a few bits of
I have the following: sets = DataSet.all.group_by{ |data| [data.project_id, -, data.thread_id].join( ) } <%
I have following script that executes all the .reg files in the current directory.
The essence of the situation comes down to the following: I have a data
I have a list of datasets. Each dataset contains one month of some data.
I have the following data: t4.8k 1.84 1.86 1.83 t5.8k 1.82 1.84 1.8 t7.10k
I have the following query that returns exactly what I need, var dataRows =
I have the following data in my dataset Type | Code | Value C1
I have the following code: As you can see, i need to pass a
I have following data GROUP_ID INDEX NULL 1 1 2 NULL 3 1 4

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.