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

Commitee92312

Browse files
committed
implement xtick rotation mode
1 parent0439b37 commitee92312

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

‎lib/matplotlib/axis.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ def _apply_params(self, **kwargs):
346346
ifkin_gridline_param_names}
347347
self.gridline.set(**grid_kw)
348348

349+
if'rotation_mode'inkwargs:
350+
rotation_mode=kwargs.pop('rotation_mode')
351+
self.label1.set_rotation_mode(rotation_mode)
352+
self.label2.set_rotation_mode(rotation_mode)
353+
349354
defupdate_position(self,loc):
350355
"""Set the location of tick in data coords with scalar *loc*."""
351356
raiseNotImplementedError('Derived must override')
@@ -1072,7 +1077,7 @@ def _translate_tick_params(kw, reverse=False):
10721077
'tick1On','tick2On','label1On','label2On',
10731078
'length','direction','left','bottom','right','top',
10741079
'labelleft','labelbottom','labelright','labeltop',
1075-
'labelrotation',
1080+
'labelrotation','rotation_mode',
10761081
*_gridline_param_names]
10771082

10781083
keymap= {

‎lib/matplotlib/text.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def set_rotation_mode(self, m):
310310
ifmisNone:
311311
m="default"
312312
else:
313-
_api.check_in_list(("anchor","default"),rotation_mode=m)
313+
_api.check_in_list(("anchor","default","xtick"),rotation_mode=m)
314314
self._rotation_mode=m
315315
self.stale=True
316316

@@ -453,7 +453,24 @@ def _get_layout(self, renderer):
453453
valign=self._verticalalignment
454454

455455
rotation_mode=self.get_rotation_mode()
456+
457+
defha_for_angle(angle):
458+
"""
459+
Determines horizontal alignment ('ha') based on the angle of rotation.
460+
"""
461+
if (angle<20or80<=angle<110or340<=angle<=360or
462+
160<=angle<200or240<=angle<300):
463+
return'center'
464+
elif20<=angle<80or200<=angle<240:
465+
return'right'
466+
elif110<=angle<160or300<=angle<340:
467+
return'left'
468+
456469
ifrotation_mode!="anchor":
470+
ifrotation_mode=='xtick':
471+
# Compute horizontal alignment based on the angle
472+
angle=self.get_rotation()
473+
halign=ha_for_angle(angle)# Use Tim's function
457474
# compute the text location in display coords and the offsets
458475
# necessary to align the bbox with that location
459476
ifhalign=='center':

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp