Skip to content

Commit e86df6f

Browse files
committed
Adds axis.orient functionality
1 parent 5f84228 commit e86df6f

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

mplaltair/_axis.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ def _set_label_angle(channel, ax):
226226
# Rotate the labels on the x-axis so they don't run into each other.
227227
label.set_rotation(30)
228228
label.set_ha('right')
229-
230229

231230
def _set_axis_title(channel, ax):
232231
'''Sets the axis label
@@ -269,6 +268,37 @@ def _set_axis_label_visibility(channel, ax):
269268
elif channel.name == 'y':
270269
ax.tick_param(labelleft=labels, labelright=labels)
271270

271+
def _set_axis_orientation(channel, ax):
272+
'''Set the axis orientation
273+
274+
Parameters
275+
----------
276+
channel: parse_chart.ChannelMetadata
277+
The channel data and metadata
278+
ax: maptlotlib.axes
279+
The matplotlib axis to be modified
280+
'''
281+
orient = channel.axis.get('orient')
282+
283+
if orient is None:
284+
if channel.name == 'x':
285+
orient = 'bottom'
286+
elif channel.name == 'y':
287+
orient = 'left'
288+
289+
ACTIONS = {
290+
'x': {
291+
'top': ax.xaxis.tick_top,
292+
'bottom': ax.xaxis.tick_bottom
293+
},
294+
'y': {
295+
'left': ax.xaxis.tick_left,
296+
'right': ax.xaxis.tick_right
297+
}
298+
}
299+
300+
ACTIONS[enc][orient]()
301+
272302
def convert_axis(ax, chart):
273303
"""Convert elements of the altair chart to Matplotlib axis properties
274304
@@ -287,3 +317,4 @@ def convert_axis(ax, chart):
287317
_set_label_angle(channel, ax)
288318
_set_axis_title(channel, ax)
289319
_set_axis_label_visibility(channel, ax)
320+
_set_axis_orientation(channel, ax)

0 commit comments

Comments
 (0)