Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd2fa4cd

Browse files
committed
Rotate caps on polar errorbar plots
1 parentecab6de commitd2fa4cd

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Polar errorbar caps are rotated
2+
-------------------------------
3+
When plotting errorbars on a polar plot, the caps are now rotated so they are
4+
perpendicular to the errorbars.

‎lib/matplotlib/axes/_axes.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3522,10 +3522,11 @@ def _upcast_err(err):
35223522
eb_cap_style['color']=ecolor
35233523

35243524
barcols= []
3525-
caplines=[]
3525+
caplines={'x': [],'y': []}
35263526

35273527
# Vectorized fancy-indexer.
3528-
defapply_mask(arrays,mask):return [array[mask]forarrayinarrays]
3528+
defapply_mask(arrays,mask):
3529+
return [array[mask]forarrayinarrays]
35293530

35303531
# dep: dependent dataset, indep: independent dataset
35313532
for (dep_axis,dep,err,lolims,uplims,indep,lines_func,
@@ -3571,7 +3572,7 @@ def apply_mask(arrays, mask): return [array[mask] for array in arrays]
35713572
line=mlines.Line2D(indep_masked,indep_masked,
35723573
marker=marker,**eb_cap_style)
35733574
line.set(**{f"{dep_axis}data":lh_masked})
3574-
caplines.append(line)
3575+
caplines[dep_axis].append(line)
35753576
foridx, (lims,hl)inenumerate([(lolims,high), (uplims,low)]):
35763577
ifnotlims.any():
35773578
continue
@@ -3585,15 +3586,36 @@ def apply_mask(arrays, mask): return [array[mask] for array in arrays]
35853586
line=mlines.Line2D(x_masked,y_masked,
35863587
marker=hlmarker,**eb_cap_style)
35873588
line.set(**{f"{dep_axis}data":hl_masked})
3588-
caplines.append(line)
3589+
caplines[dep_axis].append(line)
35893590
ifcapsize>0:
3590-
caplines.append(mlines.Line2D(
3591+
caplines[dep_axis].append(mlines.Line2D(
35913592
x_masked,y_masked,marker=marker,**eb_cap_style))
3592-
3593-
forlincaplines:
3594-
self.add_line(l)
3593+
ifself.name=='polar':
3594+
foraxisincaplines:
3595+
ifnotcaplines[axis]:
3596+
continue
3597+
lo,hi=caplines[axis]
3598+
for (lo_theta,lo_r,
3599+
hi_theta,hi_r)inzip(
3600+
lo.get_xdata(),lo.get_ydata(),
3601+
hi.get_xdata(),hi.get_ydata()):
3602+
# Rotate caps to be perpendicular to the error bars
3603+
rotation= (lo_theta+hi_theta)/2
3604+
ifaxis=='x':
3605+
rotation+=np.pi/2
3606+
ms=mmarkers.MarkerStyle(marker=marker)
3607+
ms._transform=mtransforms.Affine2D().rotate(rotation)
3608+
self.add_line(mlines.Line2D([lo_theta], [lo_r],
3609+
marker=ms,**eb_cap_style))
3610+
self.add_line(mlines.Line2D([hi_theta], [hi_r],
3611+
marker=ms,**eb_cap_style))
3612+
else:
3613+
foraxisincaplines:
3614+
forlincaplines[axis]:
3615+
self.add_line(l)
35953616

35963617
self._request_autoscale_view()
3618+
caplines=caplines['x']+caplines['y']
35973619
errorbar_container=ErrorbarContainer(
35983620
(data_line,tuple(caplines),tuple(barcols)),
35993621
has_xerr=(xerrisnotNone),has_yerr=(yerrisnotNone),

‎lib/matplotlib/tests/test_axes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3600,6 +3600,16 @@ def test_errorbar():
36003600
ax.set_title("Simplest errorbars, 0.2 in x, 0.4 in y")
36013601

36023602

3603+
@image_comparison(['errorbar_polar_caps'],extensions=['png'])
3604+
deftest_errorbar_polar_caps():
3605+
fig=plt.figure()
3606+
ax=plt.subplot(111,projection='polar')
3607+
theta=np.arange(0,2*np.pi,np.pi/4)
3608+
r=theta/np.pi/2+0.5
3609+
ax.errorbar(theta,r,xerr=0.15,yerr=0.1)
3610+
ax.set_rlim(0,2)
3611+
3612+
36033613
deftest_errorbar_colorcycle():
36043614

36053615
f,ax=plt.subplots()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp