Skip to content

Instantly share code, notes, and snippets.

@kdorr
kdorr / ChartParser.py
Last active August 10, 2018 16:51
Class structure to parse Altair Charts and store data and metadata.
from ._data import (_locate_channel_data, _locate_channel_axis, _locate_channel_field, _locate_channel_scale,
_locate_channel_dtype, _convert_to_mpl_date)
class Channel(object):
"""
Stores relevant encoding channel information.
Attributes
----------
channel : str
def _line_division(chart, ax):
"""Convert encodings, manipulate data if needed, plot on ax.
Parameters
----------
chart : altair.Chart
The Altair chart object
ax
The Matplotlib axes object
Notes
-----
@kdorr
kdorr / _data.py
Created August 8, 2018 15:54
Idea for adding _normalize_data() back.
def _normalize_data(chart):
"""Converts the data to a Pandas dataframe. Originally Nabarun's code (PR #5).
Parameters
----------
chart : altair.Chart
The Altair chart object
"""
spec = chart.to_dict()
if not spec['data']:
from ._convert import _convert
def convert(chart):
"""Convert an altair encoding to a Matplotlib figure
Parameters
----------
chart
The Altair chart object generated by Altair