Skip to content

Commit 912fc64

Browse files
committed
Start labelAngle
1 parent a031e0c commit 912fc64

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

mplaltair/_axis.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,6 @@ def _set_tick_formatter(channel, axis):
172172
"Currently, %L, %Q, and %s are allowed in Altair, but not allowed in Matplotlib."
173173
"Please use a `strftime` compliant format string.")
174174

175-
176-
# TODO: move rotation to another function?
177-
if channel['axis'] == 'x':
178-
for label in channel['ax'].get_xticklabels():
179-
# Rotate the labels on the x-axis so they don't run into each other.
180-
label.set_rotation(30)
181-
label.set_ha('right')
182-
183175
elif channel['dtype'] == 'quantitative':
184176
if format_str:
185177
current_axis[channel['axis']].set_major_formatter(ticker.StrMethodFormatter('{x:' + format_str + '}'))
@@ -195,6 +187,23 @@ def _set_tick_formatter(channel, axis):
195187
raise NotImplementedError # Nominal and Ordinal go here
196188

197189

190+
def _set_label_angle(channel, axis):
191+
"""Set the label angle. TODO: handle axis.labelAngle from Altair
192+
193+
Parameters
194+
----------
195+
channel : dict
196+
The mapping of the channel data and metadata
197+
axis : dict
198+
The mapping of the axis metadata and the scale data
199+
"""
200+
if channel['dtype'] == 'temporal' and channel['axis'] == 'x':
201+
for label in channel['ax'].get_xticklabels():
202+
# Rotate the labels on the x-axis so they don't run into each other.
203+
label.set_rotation(30)
204+
label.set_ha('right')
205+
206+
198207
def convert_axis(ax, chart):
199208
"""Convert elements of the altair chart to Matplotlib axis properties
200209
@@ -220,3 +229,4 @@ def convert_axis(ax, chart):
220229
_set_limits(chart_info, scale_info)
221230
_set_tick_locator(chart_info, axis_info)
222231
_set_tick_formatter(chart_info, axis_info)
232+
_set_label_angle(chart_info, axis_info)

0 commit comments

Comments
 (0)