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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:12:08+00:00 2026-06-17T07:12:08+00:00

How to plot multiple bars in matplotlib, when I tried to call the bar

  • 0

How to plot multiple bars in matplotlib, when I tried to call the bar function multiple times, they overlap and as seen the below figure the highest value red can be seen only.
How can I plot the multiple bars with dates on the x-axes?

So far, I tried this:

import matplotlib.pyplot as plt
import datetime

x = [
    datetime.datetime(2011, 1, 4, 0, 0),
    datetime.datetime(2011, 1, 5, 0, 0),
    datetime.datetime(2011, 1, 6, 0, 0)
]
y = [4, 9, 2]
z = [1, 2, 3]
k = [11, 12, 13]

ax = plt.subplot(111)
ax.bar(x, y, width=0.5, color='b', align='center')
ax.bar(x, z, width=0.5, color='g', align='center')
ax.bar(x, k, width=0.5, color='r', align='center')
ax.xaxis_date()

plt.show()

I got this:

enter image description here

The results should be something like, but with the dates are on the x-axes and bars are next to each other:

enter image description 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-06-17T07:12:09+00:00Added an answer on June 17, 2026 at 7:12 am
    import matplotlib.pyplot as plt
    from matplotlib.dates import date2num
    import datetime
    
    x = [
        datetime.datetime(2011, 1, 4, 0, 0),
        datetime.datetime(2011, 1, 5, 0, 0),
        datetime.datetime(2011, 1, 6, 0, 0)
    ]
    x = date2num(x)
    
    y = [4, 9, 2]
    z = [1, 2, 3]
    k = [11, 12, 13]
    
    ax = plt.subplot(111)
    ax.bar(x-0.2, y, width=0.2, color='b', align='center')
    ax.bar(x, z, width=0.2, color='g', align='center')
    ax.bar(x+0.2, k, width=0.2, color='r', align='center')
    ax.xaxis_date()
    
    plt.show()
    

    enter image description here

    I don’t know what’s the “y values are also overlapping” means, does the following code solve your problem?

    ax = plt.subplot(111)
    w = 0.3
    ax.bar(x-w, y, width=w, color='b', align='center')
    ax.bar(x, z, width=w, color='g', align='center')
    ax.bar(x+w, k, width=w, color='r', align='center')
    ax.xaxis_date()
    ax.autoscale(tight=True)
    
    plt.show()
    

    enter image description here

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

Sidebar

Related Questions

I'm trying to write a function that plots a ggplot facet_wrap plot over multiple
I have the need to build a function that will plot multiple pdfs, read
I am trying to output multiple density plot from a function, by dividing the
I'm creating a plot with multiple linetypes, colors, and filled regions.The code below produces
Whenever, I want to plot multiple 2d line graphs graphs with matplotlib, I define
I have multiple datasets I want to plot in a single figure: plot data1a.txt,
I am trying to plot roots of a function that is composed of multiple
I want to plot multiple rowstacked histograms on the same graph using gnuplot. A
I need to plot multiple sphere and I was using the example code from
Is there a way to plot multiple data for the same value x? For

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.