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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:56:40+00:00 2026-05-25T02:56:40+00:00

I want to create a polar bar plot with error bars in matplotlib. When

  • 0

I want to create a polar bar plot with error bars in matplotlib. When I use the following code all my error bars have a horizontal alignment, and it looks wrong, unless the bar corresponds to the 90 or 270 degree case.

from numpy import *
from matplotlib import pyplot as py


r=zeros([16])
err=zeros([16]) 
for i in range(16):
    r[i]=random.randint(400,600)
    err[i]=random.randint(20,50)
theta=arange(0,2*pi,2*pi/16)
width = pi*2/16

fig = py.figure(figsize=(8,8))
ax = fig.add_axes([0.1, 0.1, 0.75, 0.79], polar=True)

bars = ax.bar(theta+pi/16, r, width=width, bottom=0.0,yerr=err)
ax.set_ylim(0,700)
py.show()

the figure

How to I get the error bars to take the theta of the individual bar into account?

  • 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-25T02:56:41+00:00Added an answer on May 25, 2026 at 2:56 am

    So, it appears that the error bars are created with a Line2D object; that is, a dashed line is plotted with data points corresponding to the error bar positions (x[i],y[i]+yerr[i]). The dashes in the line are always the same, because they are just symbols. This obviously does not work for the polar plot. So this error bar setup needs to be deleted and each error bar must be added individually, with a line having the correct orientation.

    Here is a routine that does this:

    from matplotlib.lines import Line2D
    from math import acos,sqrt
    
    def correct_errorbar(ax,barlen=50,errorline=1):
        """
        A routine to remove default y-error bars on a bar-based pie chart and 
        replace them  with custom error bars that rotate with the pie chart.
        ax -- the axes object that contains the polar coordinate bar chart
        barlen -- the perpendicular length of each error bar
        errorline -- the number of the Line2D object that represents the original
           horizontal error bars.
    
        barlen will depend on the magnitude of the "y" values, ie the radius. 
        This routine was tested with a plot consisting solely of bar chart, and 
        if other Line2D objects are added, either directly or through further
        plot commands, errorline many need to be adjusted from its default value. 
        """
        # get error bar positions
        x,y = ax.lines[errorline].get_data()
        # remove incorrect bars
        del ax.lines[errorline]
        # add new lines fixing bars
        for i in range(len(y)):
            r = sqrt(barlen*barlen/4+y[i]*y[i])
            dt = acos((y[i])/(r))
            newline = Line2D([x[i]-dt,x[i]+dt],[r,r],lw=barlen/100.)
            ax.add_line(newline)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want create XML file here is my following code String fileName = jasstech.xml;
I want to create an allocator which provides memory with the following attributes: cannot
I want create a process under another user. So I use LogonUser and CreateProcessAsUser.
I want create a loading progress bar like Gmail in center and top of
I want create object from Canvas3D class(in java) but my Compiler doesn't have this
I have 4 small JPEG images (40px x 30px) and I want create an
my question is simple. I have class TouchSurfaceView which extends GLSurfaceView. I want create
I want create a drop shadow around the canvas component in flex. Technically speaking
I want to create a Java application bundle for Mac without using Mac. According
I want to create a client side mail creator web page. I know 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.