|
48 | 48 | "\n", |
49 | 49 | "templated_fig = pio.to_templated(fig)\n", |
50 | 50 | "pio.templates['my_template'] = templated_fig.layout.template\n", |
51 | | - "pio.templates.default = 'my_template'" |
52 | | - ] |
53 | | - }, |
54 | | - { |
55 | | - "cell_type": "code", |
56 | | - "execution_count": null, |
57 | | - "metadata": {}, |
58 | | - "outputs": [], |
59 | | - "source": [ |
60 | | - "from io import BytesIO\n", |
61 | | - "\n", |
62 | | - "def render_altair(chart):\n", |
63 | | - " b = BytesIO()\n", |
64 | | - " chart.save(b, scale_factor=2.0, format='png', webdriver='firefox')\n", |
65 | | - " b.seek(0)\n", |
66 | | - " return b.read()\n", |
67 | | - "\n", |
68 | | - "\n", |
69 | | - "import ast\n", |
| 51 | + "pio.templates.default = 'my_template'\n", |
70 | 52 | "\n", |
71 | | - "def exec_then_eval(code, shell):\n", |
72 | | - " block = ast.parse(code, mode='exec')\n", |
73 | | - "\n", |
74 | | - " # assumes last node is an expression\n", |
75 | | - " last = ast.Expression(block.body.pop().value)\n", |
76 | | - "\n", |
77 | | - " _globals, _locals = {}, {}\n", |
78 | | - " shell.ex(compile(block, '<string>', mode='exec'))\n", |
79 | | - " return shell.ev(compile(last, '<string>', mode='eval'))\n", |
80 | | - "\n", |
81 | | - "@magics_class\n", |
82 | | - "class AltairMagic(Magics):\n", |
83 | | - " @cell_magic\n", |
84 | | - " def altair(self, line, cell):\n", |
85 | | - " return Image(render_altair(exec_then_eval(cell, self.shell)))\n", |
86 | | - "\n", |
87 | | - "\n", |
88 | | - "ip = get_ipython()\n", |
89 | | - "ip.register_magics(AltairMagic)" |
| 53 | + "alt.renderers.enable('png', webdriver='firefox')" |
90 | 54 | ] |
91 | 55 | }, |
92 | 56 | { |
|
109 | 73 | "theme_set(theme_grey(base_size = 24))" |
110 | 74 | ] |
111 | 75 | }, |
112 | | - { |
113 | | - "cell_type": "code", |
114 | | - "execution_count": null, |
115 | | - "metadata": {}, |
116 | | - "outputs": [], |
117 | | - "source": [] |
118 | | - }, |
119 | 76 | { |
120 | 77 | "cell_type": "markdown", |
121 | 78 | "metadata": {}, |
|
354 | 311 | }, |
355 | 312 | "outputs": [], |
356 | 313 | "source": [ |
357 | | - "%%altair\n", |
358 | 314 | "(\n", |
359 | 315 | " alt.Chart(\n", |
360 | 316 | " mpg, title=\"Number of Cars by Make\"\n", |
|
475 | 431 | }, |
476 | 432 | "outputs": [], |
477 | 433 | "source": [ |
478 | | - "%%altair\n", |
479 | 434 | "(\n", |
480 | 435 | " alt.Chart(mpg)\n", |
481 | 436 | " .mark_bar()\n", |
|
566 | 521 | }, |
567 | 522 | "outputs": [], |
568 | 523 | "source": [ |
569 | | - "%%altair \n", |
570 | 524 | "alt.Chart(mpg).mark_circle().encode(\n", |
571 | 525 | " alt.X(\n", |
572 | 526 | " \"displ\",\n", |
|
813 | 767 | }, |
814 | 768 | "outputs": [], |
815 | 769 | "source": [ |
816 | | - "%%altair \n", |
817 | 770 | "(\n", |
818 | 771 | " alt.Chart(\n", |
819 | 772 | " mpg,\n", |
|
948 | 901 | }, |
949 | 902 | "outputs": [], |
950 | 903 | "source": [ |
951 | | - "%%altair\n", |
952 | 904 | "(\n", |
953 | 905 | " alt.Chart(\n", |
954 | 906 | " mpg,\n", |
|
1068 | 1020 | }, |
1069 | 1021 | "outputs": [], |
1070 | 1022 | "source": [ |
1071 | | - "%%altair \n", |
1072 | 1023 | "alt.Chart(mpg).mark_circle().encode(\n", |
1073 | 1024 | " x=alt.X(\"displ\"),\n", |
1074 | 1025 | " y=alt.Y(\"hwy\"),\n", |
|
1190 | 1141 | }, |
1191 | 1142 | "outputs": [], |
1192 | 1143 | "source": [ |
1193 | | - "%%altair \n", |
1194 | 1144 | "(alt\n", |
1195 | 1145 | " .Chart(mpg)\n", |
1196 | 1146 | " .mark_circle()\n", |
|
1306 | 1256 | }, |
1307 | 1257 | "outputs": [], |
1308 | 1258 | "source": [ |
1309 | | - "%%altair\n", |
1310 | 1259 | "scatter = (\n", |
1311 | 1260 | " alt.Chart(\n", |
1312 | 1261 | " mpg,\n", |
|
1463 | 1412 | }, |
1464 | 1413 | "outputs": [], |
1465 | 1414 | "source": [ |
1466 | | - "%%altair\n", |
1467 | 1415 | "alt.data_transformers.disable_max_rows()\n", |
1468 | 1416 | "alt.Chart(diamonds).mark_bar().encode(\n", |
1469 | 1417 | " x=\"cut\", y=\"count(cut)\", color=\"clarity\"\n", |
|
1552 | 1500 | }, |
1553 | 1501 | "outputs": [], |
1554 | 1502 | "source": [ |
1555 | | - "%%altair\n", |
1556 | 1503 | "alt.data_transformers.disable_max_rows()\n", |
1557 | 1504 | "alt.Chart(diamonds).mark_bar().encode(\n", |
1558 | 1505 | " x=\"clarity\",\n", |
|
1727 | 1674 | }, |
1728 | 1675 | "outputs": [], |
1729 | 1676 | "source": [ |
1730 | | - "%%altair\n", |
1731 | 1677 | "alt.data_transformers.disable_max_rows()\n", |
1732 | 1678 | "alt.Chart(diamonds).transform_density(\n", |
1733 | 1679 | " \"depth\",\n", |
|
1849 | 1795 | }, |
1850 | 1796 | "outputs": [], |
1851 | 1797 | "source": [ |
1852 | | - "%%altair \n", |
1853 | 1798 | "alt.Chart(ts).mark_line().encode(\n", |
1854 | 1799 | " x=\"date\", y=\"value\"\n", |
1855 | 1800 | ")" |
|
0 commit comments