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

Commit069fac1

Browse files
committed
Ensure polar axis labels see both tick directions
Since these labels are currently just an x/y analog (and not tied to theaxis orientation), they need to "see" the other axis in order to avoidoverlap.
1 parente1d2781 commit069fac1

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

‎lib/matplotlib/projections/polar.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,30 @@ class ThetaAxis(maxis.XAxis):
386386
axis_name='theta'#: Read-only name identifying the axis.
387387
_tick_class=ThetaTick
388388

389+
def_update_label_position(self,renderer):
390+
"""
391+
Update the label position based on the bounding box enclosing
392+
all the ticklabels and axis spine
393+
"""
394+
ifnotself._autolabelpos:
395+
return
396+
397+
# get bounding boxes for this axis and any siblings
398+
# that have been set by `fig.align_xlabels()`
399+
xbboxes,xbboxes2=self._get_tick_boxes_siblings(renderer=renderer)
400+
ybboxes,ybboxes2=self.axes.yaxis._get_tick_boxes_siblings(renderer=renderer)
401+
# Union with extents of the bottom spine if present, of the axes otherwise.
402+
bbox=mtransforms.Bbox.union([
403+
*xbboxes,*xbboxes2,*ybboxes,*ybboxes2,
404+
self.axes.spines.get(self.label_position,self.axes).get_window_extent()])
405+
406+
x,y=self.label.get_position()
407+
ifself.label_position=='bottom':
408+
y=bbox.y0-self.labelpad*self.get_figure(root=True).dpi/72
409+
else:
410+
y=bbox.y1+self.labelpad*self.get_figure(root=True).dpi/72
411+
self.label.set_position((x,y))
412+
389413
def_wrap_locator_formatter(self):
390414
self.set_major_locator(ThetaLocator(self.get_major_locator()))
391415
self.set_major_formatter(ThetaFormatter())
@@ -679,6 +703,30 @@ def __init__(self, *args, **kwargs):
679703
super().__init__(*args,**kwargs)
680704
self.sticky_edges.y.append(0)
681705

706+
def_update_label_position(self,renderer):
707+
"""
708+
Update the label position based on the bounding box enclosing
709+
all the ticklabels and axis spine
710+
"""
711+
ifnotself._autolabelpos:
712+
return
713+
714+
# get bounding boxes for this axis and any siblings
715+
# that have been set by `fig.align_xlabels()`
716+
xbboxes,xbboxes2=self._get_tick_boxes_siblings(renderer=renderer)
717+
ybboxes,ybboxes2=self.axes.xaxis._get_tick_boxes_siblings(renderer=renderer)
718+
# Union with extents of the linked spine if present, of the axes otherwise.
719+
bbox=mtransforms.Bbox.union([
720+
*xbboxes,*xbboxes2,*ybboxes,*ybboxes2,
721+
self.axes.spines.get(self.label_position,self.axes).get_window_extent()])
722+
723+
x,y=self.label.get_position()
724+
ifself.label_position=='left':
725+
x=bbox.x0-self.labelpad*self.get_figure(root=True).dpi/72
726+
else:
727+
x=bbox.x1+self.labelpad*self.get_figure(root=True).dpi/72
728+
self.label.set_position((x,y))
729+
682730
def_wrap_locator_formatter(self):
683731
self.set_major_locator(RadialLocator(self.get_major_locator(),
684732
self.axes))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp