Skip to content

Commit fcb6af4

Browse files
committed
Adds axis label setters
1 parent 337ab54 commit fcb6af4

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

mplaltair/_axis.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,30 @@ def _set_label_angle(channel, ax):
209209
label.set_rotation(30)
210210
label.set_ha('right')
211211

212+
def _set_axis_title(channel, ax):
213+
'''Sets the axis label
214+
215+
Currently, does not support aggregated, binned or timeUnit specified channels
216+
217+
Parameters
218+
----------
219+
channel: parse_chart.ChannelMetadata
220+
The channel data and metadata
221+
ax: maptlotlib.axes
222+
The matplotlib axis to be modified
223+
'''
224+
if channel.title:
225+
if channel.name == 'x':
226+
ax.set_xlabel(title)
227+
elif channel.name == 'y':
228+
ax.set_ylabel(title)
229+
elif channel.aggregate:
230+
raise NotImplementedError
231+
elif channel.bin:
232+
raise NotImplementedError
233+
elif channel.timeUnit:
234+
raise NotImplementedError
235+
212236

213237
def convert_axis(ax, chart):
214238
"""Convert elements of the altair chart to Matplotlib axis properties
@@ -226,3 +250,4 @@ def convert_axis(ax, chart):
226250
_set_tick_locator(channel, ax)
227251
_set_tick_formatter(channel, ax)
228252
_set_label_angle(channel, ax)
253+
_set_axis_title(channel, ax)

mplaltair/parse_chart.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class ChannelMetadata(object):
1111
The name of the encoding channel
1212
data : np.array
1313
The data linked to the channel (temporal data is converted)
14+
aggregate : str or dict
1415
axis : dict
1516
bin : boolean, None
1617
field : str
@@ -25,6 +26,7 @@ def __init__(self, channel, alt_chart):
2526
chart_dict = alt_chart.to_dict()
2627
self.name = channel
2728
self.data = self._locate_channel_data(alt_chart)
29+
self.aggregate = chart_dict['encoding'][self.name].get('aggregate', {})
2830
self.axis = chart_dict['encoding'][self.name].get('axis', {})
2931
self.bin = chart_dict['encoding'][self.name].get('bin', None)
3032
self.field = chart_dict['encoding'][self.name].get('field', None)

0 commit comments

Comments
 (0)