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

Commitd8fa323

Browse files
committed
Add an 'auto' option to label rotation.
This option enables the automatic rotation of polar tick labels.
1 parent67b86c6 commitd8fa323

File tree

4 files changed

+49
-12
lines changed

4 files changed

+49
-12
lines changed

‎doc/users/whats_new.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@ negative values are simply used as labels, and the real radius is shifted by
6262
the configured minimum. This release also allows negative radii to be used for
6363
grids and ticks, which were previously silently ignored.
6464

65-
For plots of a partial circle, radial ticks and tick labels have been modified
66-
to be parallel to the circular grid line. Angular ticks have been modified to
67-
be parallel to the grid line and the labels are now perpendicular to the grid
68-
line (i.e., parallel to the outer boundary.)
65+
Radial ticks have be modified to be parallel to the circular grid line. Angular
66+
ticks will be modified to be parallel to the grid line. It may also be useful
67+
to rotate tick labels to match the boundary. Calling
68+
``ax.tick_params(rotation='auto')`` will enable this new behavior. Radial tick
69+
labels will be modified to be parallel to the circular grid line. Angular tick
70+
labels will be perpendicular to the grid line (i.e., parallel to the outer
71+
boundary.)
6972

7073

7174
Merge JSAnimation

‎lib/matplotlib/axis.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def __init__(self, axes, loc, label,
140140
labelsize=rcParams['%s.labelsize'%name]
141141
self._labelsize=labelsize
142142

143-
self._labelrotation=labelrotation
143+
self._set_labelrotation(labelrotation)
144144

145145
ifzorderisNone:
146146
ifmajor:
@@ -167,6 +167,20 @@ def __init__(self, axes, loc, label,
167167

168168
self.update_position(loc)
169169

170+
def_set_labelrotation(self,labelrotation):
171+
ifisinstance(labelrotation,six.string_types):
172+
mode=labelrotation
173+
angle=0
174+
elifisinstance(labelrotation, (tuple,list)):
175+
mode,angle=labelrotation
176+
else:
177+
mode='default'
178+
angle=labelrotation
179+
ifmodenotin ('auto','default'):
180+
raiseValueError("Label rotation mode must be 'default' or "
181+
"'auto', not '{}'.".format(mode))
182+
self._labelrotation= (mode,angle)
183+
170184
defapply_tickdir(self,tickdir):
171185
"""
172186
Calculate self._pad and self._tickmarkers
@@ -331,8 +345,14 @@ def _apply_params(self, **kw):
331345
self.tick2line.set(**tick_kw)
332346
fork,vinsix.iteritems(tick_kw):
333347
setattr(self,'_'+k,v)
348+
349+
if'labelrotation'inkw:
350+
self._set_labelrotation(kw.pop('labelrotation'))
351+
self.label1.set(rotation=self._labelrotation[1])
352+
self.label2.set(rotation=self._labelrotation[1])
353+
334354
label_list= [kforkinsix.iteritems(kw)
335-
ifk[0]in ['labelsize','labelcolor','labelrotation']]
355+
ifk[0]in ['labelsize','labelcolor']]
336356
iflabel_list:
337357
label_kw= {k[5:]:vfork,vinlabel_list}
338358
self.label1.set(**label_kw)

‎lib/matplotlib/projections/polar.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from __future__import (absolute_import,division,print_function,
22
unicode_literals)
33

4+
importsix
5+
46
fromcollectionsimportOrderedDict
57

68
importnumpyasnp
@@ -322,14 +324,17 @@ def update_position(self, loc):
322324
trans=self.tick2line._marker._transform
323325
self.tick2line._marker._transform=trans
324326

325-
ifnot_is_full_circle_deg(axes.get_thetamin(),axes.get_thetamax()):
327+
mode,user_angle=self._labelrotation
328+
ifmode=='default':
329+
angle=0
330+
elifnot_is_full_circle_deg(axes.get_thetamin(),axes.get_thetamax()):
326331
ifangle>np.pi/2:
327332
angle-=np.pi
328333
elifangle<-np.pi/2:
329334
angle+=np.pi
330335
else:
331336
angle=0
332-
angle=np.rad2deg(angle)+self._labelrotation
337+
angle=np.rad2deg(angle)+user_angle
333338
ifself.label1On:
334339
self.label1.set_rotation(angle)
335340
ifself.label2On:
@@ -539,7 +544,11 @@ def update_position(self, loc):
539544
text_angle=angle+180
540545
else:
541546
text_angle=angle
542-
text_angle+=self._labelrotation
547+
mode,user_angle=self._labelrotation
548+
ifmode=='auto':
549+
text_angle+=user_angle
550+
else:
551+
text_angle=user_angle
543552
ifself.label1On:
544553
iffull:
545554
ha='left'
@@ -583,7 +592,11 @@ def update_position(self, loc):
583592
text_angle=angle+180
584593
else:
585594
text_angle=angle
586-
text_angle+=self._labelrotation
595+
mode,user_angle=self._labelrotation
596+
ifmode=='auto':
597+
text_angle+=user_angle
598+
else:
599+
text_angle=user_angle
587600
ifself.label2On:
588601
ha,va=self._determine_anchor(angle,False)
589602
self.label2.set_ha(ha)

‎lib/matplotlib/tests/test_axes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,9 @@ def test_polar_theta_limits():
692692
ax.set_thetamin(start)
693693
ax.set_thetamax(end)
694694
ax.tick_params(tick1On=True,tick2On=True,
695-
direction=DIRECTIONS[i%len(DIRECTIONS)])
696-
ax.yaxis.set_tick_params(label2On=True)
695+
direction=DIRECTIONS[i%len(DIRECTIONS)],
696+
rotation='auto')
697+
ax.yaxis.set_tick_params(label2On=True,rotation='auto')
697698
else:
698699
ax.set_visible(False)
699700

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp