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

  • Home
  • SEARCH
  • 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 8250709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:59:16+00:00 2026-06-07T23:59:16+00:00

I use a bar graph to indicate the data of each group. Some of

  • 0

I use a bar graph to indicate the data of each group. Some of these bars differ significantly from each other. How can I indicate the significant difference in the bar plot?

import numpy as np
import matplotlib.pyplot as plt
menMeans   = (5, 15, 30, 40)
menStd     = (2, 3, 4, 5)
ind = np.arange(4)    # the x locations for the groups
width=0.35
p1 = plt.bar(ind, menMeans, width=width, color='r', yerr=menStd)
plt.xticks(ind+width/2., ('A', 'B', 'C', 'D') )

I am aiming for

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-07T23:59:18+00:00Added an answer on June 7, 2026 at 11:59 pm

    I’ve done a couple of things here that I suggest when working with complex plots. Pull out the custom formatting into a dictionary, it makes life simple when you want to change a parameter – and you can pass this dictionary to multiple plots. I’ve also written a custom function to annotate the itervalues, as a bonus it can annotate between (A,C) if you really want to (I stand by my comment that this isn’t the right visual approach however). It may need some tweaking once the data changes but this should put you on the right track.

    import numpy as np
    import matplotlib.pyplot as plt
    menMeans   = (5, 15, 30, 40)
    menStd     = (2, 3, 4, 5)
    ind  = np.arange(4)    # the x locations for the groups
    width= 0.7
    labels = ('A', 'B', 'C', 'D')
    
    # Pull the formatting out here
    bar_kwargs = {'width':width,'color':'y','linewidth':2,'zorder':5}
    err_kwargs = {'zorder':0,'fmt':None,'linewidth':2,'ecolor':'k'}  #for matplotlib >= v1.4 use 'fmt':'none' instead
    
    fig, ax = plt.subplots()
    ax.p1 = plt.bar(ind, menMeans, **bar_kwargs)
    ax.errs = plt.errorbar(ind, menMeans, yerr=menStd, **err_kwargs)
    
    
    # Custom function to draw the diff bars
    
    def label_diff(i,j,text,X,Y):
        x = (X[i]+X[j])/2
        y = 1.1*max(Y[i], Y[j])
        dx = abs(X[i]-X[j])
    
        props = {'connectionstyle':'bar','arrowstyle':'-',\
                     'shrinkA':20,'shrinkB':20,'linewidth':2}
        ax.annotate(text, xy=(X[i],y+7), zorder=10)
        ax.annotate('', xy=(X[i],y), xytext=(X[j],y), arrowprops=props)
    
    # Call the function
    label_diff(0,1,'p=0.0370',ind,menMeans)
    label_diff(1,2,'p<0.0001',ind,menMeans)
    label_diff(2,3,'p=0.0025',ind,menMeans)
    
    
    plt.ylim(ymax=60)
    plt.xticks(ind, labels, color='k')
    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 am trying to use jqPlot for a bar graph and I can't get
For example, If I use the search bar from www.site.com I see www.site.com/search, which
I have this JPGraph (with proper data): // Create the graph. These two calls
I would like to create a stacked bar chart based on data from a
I'm setting up styles for a stacked bar graph, I would love to use
I have a couple of queries which pull data for use in a graph.
Possible Duplicate: Create a bar graph with pre-summarized data using ggplot2 On ggplot2 reference
Suppose I have a page, http://foo.com/bar . Is it possible to use the Graph
I want to use bar chart in web application. I have searched many libraries
Is it possible to use tab bar in a view instead of window? Seems

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.