Skip to content

Instantly share code, notes, and snippets.

@kdorr
Created July 31, 2018 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdorr/6adce3113f100e74f6822e537d870c20 to your computer and use it in GitHub Desktop.
Save kdorr/6adce3113f100e74f6822e537d870c20 to your computer and use it in GitHub Desktop.
from ._convert import _convert
def convert(chart):
"""Convert an altair encoding to a Matplotlib figure
Parameters
----------
chart
The Altair chart object generated by Altair
Returns
-------
fig
The Matplotlib figure
ax
The Matplotlib axes object
"""
fig, ax = plt.subplots()
if chart.mark is ('point', 'circle', 'square'): # scatter
mapping = _convert(chart)
ax.scatter(**mapping)
elif chart.mark == 'line': # line
data = _data.get_df()
if 'color' or 'stroke' in data:
for _, subset in data.groupby(color):
mapping = _convert(chart, subset)
ax.plot(**mapping)
return fig, ax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment