How to plot error diagrams in polar coordinates in python?

I have the following problem: I want to build some data points in polar coordinates in python, which is easy using some code like

import numpy as np import matplotlib.pyplot as plt r = 1e04 * np.array([5.31,5.29,5.25,5.19,5.09,4.92,4.67,4.27,3.75,3.56]) theta = 2*np.pi/360 * np.array(list(range(0, 100, 10))) plt.polar(theta, r, "ro") plt.show() 

but I want to add error lines and I have not found a sufficient solution. Is there any ready-made matplotlib code? Or does anyone know how to correctly identify error columns? As I understand it, r-error is just a straight line, and theta-error is a circle segment.

+5
source share
2 answers

When limiting the error, bar is that caps are drawn with the hline and vline , so the caps rotate incorrectly in polar coordinates (there is a problem for this, https://github.com/matplotlib/matplotlib/issues/441 ). An approximate workaround is to make caps zero:

 import numpy as np import pylab as plt fig = plt.figure() ax = plt.axes(polar=True) r = np.array([5.31,5.29,5.25,5.19,5.09,4.92,4.67,4.27,3.75,3.56]) theta = 2*np.pi/360 * np.array(list(range(0, 100, 10))) ax.plot(theta, r, "ro") ax.errorbar(theta, r, yerr=1, xerr=.1, capsize=0) plt.show() 

polar plot with error bars

If you want theta error lines to be circular, you have to implement this. The easiest way -

 th_err = 1 for th, _r in zip(theta, r): local_theta = np.linspace(-th_err, th_err, 15) + th local_r = np.ones(15) * _r ax.plot(local_theta, local_r, color='k', marker='') plt.show() 

For small errors, this will not matter much, but it will be important for large errors.

+2
source

I would recommend something like this:

 import numpy as np import pylab as plt fig = plt.figure() ax = plt.axes(polar=True) r = 1e04 * np.array([5.31,5.29,5.25,5.19,5.09,4.92,4.67,4.27,3.75,3.56]) theta = 2*np.pi/360 * np.array(list(range(0, 100, 10))) ax.plot(theta, r, "ro") ax.errorbar(theta, r, xerr=0.5, yerr=0.4) plt.show() 

But there are some problems. I do not know if pylab is pylab . View at a loss as to what to do :)

0
source

Source: https://habr.com/ru/post/1205588/


All Articles