Skip to content

Commit 5f84228

Browse files
committed
Adds axis.labelAngle functionality
1 parent f8add24 commit 5f84228

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

mplaltair/_axis.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,30 @@ def _set_label_angle(channel, ax):
203203
ax : matplotlib.axes
204204
The mapping of the axis metadata and the scale data
205205
"""
206+
207+
label_angle = channel.axis.get('labelAngle')
208+
209+
# Sets the defaults used by altair if axis.labelAngle is not specified
210+
if label_angle is None:
211+
if channel.type in ['ordinal', 'nominal']:
212+
label_angle = -90
213+
elif channel_type in ['quantitative', 'temporal']:
214+
label_angle = 0
215+
216+
if channel.name == 'x':
217+
for label in ax.get_xticklabels():
218+
label.set_rotation(-1*label_angle)
219+
elif channel.name == 'y':
220+
for label in ax.get_yticklabels():
221+
label.set_rotation(-1*label_angle)
222+
223+
# Special case for temporal encoding type to improve visual appeal
206224
if channel.type == 'temporal' and channel.name == 'x':
207225
for label in ax.get_xticklabels():
208226
# Rotate the labels on the x-axis so they don't run into each other.
209227
label.set_rotation(30)
210228
label.set_ha('right')
229+
211230

212231
def _set_axis_title(channel, ax):
213232
'''Sets the axis label

0 commit comments

Comments
 (0)