Skip to content
Permalink
Browse files

Merge pull request #19 from tdhopper/set-altair-renderer

Set altair renderer
  • Loading branch information
tdhopper committed Jan 7, 2020
2 parents 1fc9100 + 7893641 commit 034c05879db6ad72dee2c964be57402b22f485a8
Showing with 2 additions and 57 deletions.
  1. +2 −57 Examples.ipynb
@@ -48,45 +48,9 @@
"\n",
"templated_fig = pio.to_templated(fig)\n",
"pio.templates['my_template'] = templated_fig.layout.template\n",
"pio.templates.default = 'my_template'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from io import BytesIO\n",
"\n",
"def render_altair(chart):\n",
" b = BytesIO()\n",
" chart.save(b, scale_factor=2.0, format='png', webdriver='firefox')\n",
" b.seek(0)\n",
" return b.read()\n",
"\n",
"\n",
"import ast\n",
"pio.templates.default = 'my_template'\n",
"\n",
"def exec_then_eval(code, shell):\n",
" block = ast.parse(code, mode='exec')\n",
"\n",
" # assumes last node is an expression\n",
" last = ast.Expression(block.body.pop().value)\n",
"\n",
" _globals, _locals = {}, {}\n",
" shell.ex(compile(block, '<string>', mode='exec'))\n",
" return shell.ev(compile(last, '<string>', mode='eval'))\n",
"\n",
"@magics_class\n",
"class AltairMagic(Magics):\n",
" @cell_magic\n",
" def altair(self, line, cell):\n",
" return Image(render_altair(exec_then_eval(cell, self.shell)))\n",
"\n",
"\n",
"ip = get_ipython()\n",
"ip.register_magics(AltairMagic)"
"alt.renderers.enable('png', webdriver='firefox')"
]
},
{
@@ -109,13 +73,6 @@
"theme_set(theme_grey(base_size = 24))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
@@ -354,7 +311,6 @@
},
"outputs": [],
"source": [
"%%altair\n",
"(\n",
" alt.Chart(\n",
" mpg, title=\"Number of Cars by Make\"\n",
@@ -475,7 +431,6 @@
},
"outputs": [],
"source": [
"%%altair\n",
"(\n",
" alt.Chart(mpg)\n",
" .mark_bar()\n",
@@ -566,7 +521,6 @@
},
"outputs": [],
"source": [
"%%altair \n",
"alt.Chart(mpg).mark_circle().encode(\n",
" alt.X(\n",
" \"displ\",\n",
@@ -813,7 +767,6 @@
},
"outputs": [],
"source": [
"%%altair \n",
"(\n",
" alt.Chart(\n",
" mpg,\n",
@@ -948,7 +901,6 @@
},
"outputs": [],
"source": [
"%%altair\n",
"(\n",
" alt.Chart(\n",
" mpg,\n",
@@ -1068,7 +1020,6 @@
},
"outputs": [],
"source": [
"%%altair \n",
"alt.Chart(mpg).mark_circle().encode(\n",
" x=alt.X(\"displ\"),\n",
" y=alt.Y(\"hwy\"),\n",
@@ -1190,7 +1141,6 @@
},
"outputs": [],
"source": [
"%%altair \n",
"(alt\n",
" .Chart(mpg)\n",
" .mark_circle()\n",
@@ -1306,7 +1256,6 @@
},
"outputs": [],
"source": [
"%%altair\n",
"scatter = (\n",
" alt.Chart(\n",
" mpg,\n",
@@ -1463,7 +1412,6 @@
},
"outputs": [],
"source": [
"%%altair\n",
"alt.data_transformers.disable_max_rows()\n",
"alt.Chart(diamonds).mark_bar().encode(\n",
" x=\"cut\", y=\"count(cut)\", color=\"clarity\"\n",
@@ -1552,7 +1500,6 @@
},
"outputs": [],
"source": [
"%%altair\n",
"alt.data_transformers.disable_max_rows()\n",
"alt.Chart(diamonds).mark_bar().encode(\n",
" x=\"clarity\",\n",
@@ -1727,7 +1674,6 @@
},
"outputs": [],
"source": [
"%%altair\n",
"alt.data_transformers.disable_max_rows()\n",
"alt.Chart(diamonds).transform_density(\n",
" \"depth\",\n",
@@ -1849,7 +1795,6 @@
},
"outputs": [],
"source": [
"%%altair \n",
"alt.Chart(ts).mark_line().encode(\n",
" x=\"date\", y=\"value\"\n",
")"

0 comments on commit 034c058

Please sign in to comment.
You can’t perform that action at this time.