|
19 | 19 | "from plotly import figure_factory\n", |
20 | 20 | "from plotly import graph_objects\n", |
21 | 21 | "import plotly.express as px\n", |
22 | | - "import plotly.io as pio\n", |
23 | 22 | "from IPython.core.magic import Magics, magics_class, cell_magic\n", |
24 | 23 | "\n", |
25 | 24 | "from IPython.display import Image\n", |
|
45 | 44 | ") # for plotnine\n", |
46 | 45 | "\n", |
47 | 46 | "\n", |
48 | | - "fig = graph_objects.Figure(layout = dict(width=100, height=100))\n", |
49 | | - "\n", |
50 | | - "templated_fig = pio.to_templated(fig)\n", |
51 | | - "pio.templates['my_template'] = templated_fig.layout.template\n", |
52 | | - "pio.templates.default = 'my_template'\n", |
53 | | - "px.defaults.width = 100\n", |
54 | | - "px.defaults.height = 100\n", |
| 47 | + "import plotly.io as pio\n", |
55 | 48 | "pio.renderers.default = \"png\"\n", |
56 | | - "pio.renderers[\"png\"].width = 900\n", |
57 | | - "pio.renderers[\"png\"].height = 900\n", |
| 49 | + "pio.renderers[\"png\"].width = 750\n", |
| 50 | + "pio.renderers[\"png\"].height = 750\n", |
58 | 51 | "\n", |
59 | 52 | "alt.renderers.enable('png', webdriver='firefox')" |
60 | 53 | ] |
|
292 | 285 | }, |
293 | 286 | "outputs": [], |
294 | 287 | "source": [ |
295 | | - "px.histogram(mpg, y=\"manufacturer\", \n", |
296 | | - " title='Number of Cars by Make')" |
| 288 | + "px.histogram(\n", |
| 289 | + " mpg, y=\"manufacturer\", \n", |
| 290 | + " title='Number of Cars by Make'\n", |
| 291 | + ")" |
297 | 292 | ] |
298 | 293 | }, |
299 | 294 | { |
|
407 | 402 | }, |
408 | 403 | "outputs": [], |
409 | 404 | "source": [ |
410 | | - "px.histogram(mpg, x=\"cty\")" |
| 405 | + "px.histogram(\n", |
| 406 | + " mpg, x=\"cty\"\n", |
| 407 | + ")" |
411 | 408 | ] |
412 | 409 | }, |
413 | 410 | { |
|
538 | 535 | }, |
539 | 536 | "outputs": [], |
540 | 537 | "source": [ |
541 | | - "px.scatter(mpg, x=\"displ\", y=\"hwy\", \n", |
542 | | - " title='Engine Displacement in Liters vs Highway MPG',\n", |
543 | | - " labels=dict(\n", |
544 | | - " displ='Engine Displacement in Liters', \n", |
545 | | - " hwy='Highway MPG')\n", |
546 | | - " )" |
| 538 | + "px.scatter(\n", |
| 539 | + " mpg, x=\"displ\", y=\"hwy\", \n", |
| 540 | + " title='Engine Displacement in Liters vs Highway MPG',\n", |
| 541 | + " labels=dict(\n", |
| 542 | + " displ='Engine Displacement in Liters', \n", |
| 543 | + " hwy='Highway MPG')\n", |
| 544 | + ")" |
547 | 545 | ] |
548 | 546 | }, |
549 | 547 | { |
|
682 | 680 | "fig.add_trace(p2)\n", |
683 | 681 | "fig.add_trace(p3)\n", |
684 | 682 | "fig.add_trace(p4)\n", |
685 | | - "Image(fig.to_image(format=\"png\", width=900, height=900))" |
| 683 | + "Image(fig.to_image(format=\"png\", width=750, height=750))" |
686 | 684 | ] |
687 | 685 | }, |
688 | 686 | { |
|
821 | 819 | }, |
822 | 820 | "outputs": [], |
823 | 821 | "source": [ |
824 | | - "px.scatter(mpg, x=\"displ\", y=\"hwy\", color=\"class\", \n", |
825 | | - " title='Engine Displacement in Liters vs Highway MPG',\n", |
826 | | - " labels=dict(\n", |
827 | | - " displ='Engine Displacement in Liters', \n", |
828 | | - " hwy='Highway MPG')\n", |
829 | | - " )" |
| 822 | + "px.scatter(\n", |
| 823 | + " mpg, x=\"displ\", y=\"hwy\", color=\"class\", \n", |
| 824 | + " title='Engine Displacement in Liters vs Highway MPG',\n", |
| 825 | + " labels=dict(\n", |
| 826 | + " displ='Engine Displacement in Liters', \n", |
| 827 | + " hwy='Highway MPG')\n", |
| 828 | + ")" |
830 | 829 | ] |
831 | 830 | }, |
832 | 831 | { |
|
869 | 868 | "(\n", |
870 | 869 | " alt.Chart(\n", |
871 | 870 | " mpg,\n", |
872 | | - " title=\"Engine Displacement in Liters vs Highway MPG\",\n", |
| 871 | + " title=\"City MPG vs Highway MPG\",\n", |
873 | 872 | " )\n", |
874 | 873 | " .mark_circle(opacity=0.3)\n", |
875 | 874 | " .encode(\n", |
|
907 | 906 | " y='hwy', \n", |
908 | 907 | " s=10*mpg['cyl'],\n", |
909 | 908 | " alpha=.5))\n", |
910 | | - "ax.set_title('Engine Displacement in Liters vs Highway MPG')\n", |
911 | | - "ax.set_xlabel('Engine Displacement in Liters')\n", |
| 909 | + "ax.set_title('City MPG vs Highway MPG')\n", |
| 910 | + "ax.set_xlabel('City MPG')\n", |
912 | 911 | "ax.set_ylabel('Highway MPG');" |
913 | 912 | ] |
914 | 913 | }, |
|
941 | 940 | }, |
942 | 941 | "outputs": [], |
943 | 942 | "source": [ |
944 | | - "px.scatter(mpg, x=\"cty\", y=\"hwy\", size=\"cyl\", size_max=10,\n", |
945 | | - " title='City MPG vs Highway MPG',\n", |
946 | | - " labels=dict(cty='City MPG', hwy='Highway MPG')\n", |
947 | | - " )" |
| 943 | + "px.scatter(\n", |
| 944 | + " mpg, x=\"cty\", y=\"hwy\", \n", |
| 945 | + " size=\"cyl\", size_max=10,\n", |
| 946 | + " title='City MPG vs Highway MPG',\n", |
| 947 | + " labels=dict(cty='City MPG', hwy='Highway MPG')\n", |
| 948 | + ")" |
948 | 949 | ] |
949 | 950 | }, |
950 | 951 | { |
|
1045 | 1046 | }, |
1046 | 1047 | "outputs": [], |
1047 | 1048 | "source": [ |
1048 | | - "px.scatter(mpg, x=\"displ\", y=\"hwy\", facet_col=\"class\", facet_col_wrap=4)" |
| 1049 | + "px.scatter(\n", |
| 1050 | + " mpg, x=\"displ\", y=\"hwy\", \n", |
| 1051 | + " facet_col=\"class\", facet_col_wrap=4\n", |
| 1052 | + ")" |
1049 | 1053 | ] |
1050 | 1054 | }, |
1051 | 1055 | { |
|
1150 | 1154 | }, |
1151 | 1155 | "outputs": [], |
1152 | 1156 | "source": [ |
1153 | | - "px.scatter(mpg, x=\"displ\", y=\"hwy\", \n", |
1154 | | - " facet_col=\"cyl\", facet_row=\"drv\",\n", |
1155 | | - " category_orders=dict(cyl=[4,5,6,8]))" |
| 1157 | + "px.scatter(\n", |
| 1158 | + " mpg, x=\"displ\", y=\"hwy\", \n", |
| 1159 | + " facet_col=\"cyl\", facet_row=\"drv\",\n", |
| 1160 | + " category_orders=dict(cyl=[4,5,6,8])\n", |
| 1161 | + ")" |
1156 | 1162 | ] |
1157 | 1163 | }, |
1158 | 1164 | { |
|
1302 | 1308 | " }\n", |
1303 | 1309 | " }\n", |
1304 | 1310 | "})\n", |
1305 | | - "Image(fig.to_image(format=\"png\", width=900, height=900))" |
| 1311 | + "Image(fig.to_image(format=\"png\", width=750, height=750))" |
1306 | 1312 | ] |
1307 | 1313 | }, |
1308 | 1314 | { |
|
1390 | 1396 | }, |
1391 | 1397 | "outputs": [], |
1392 | 1398 | "source": [ |
1393 | | - "px.histogram(diamonds, x=\"cut\", color=\"clarity\",\n", |
1394 | | - " category_orders=dict(cut=[\n", |
1395 | | - " \"Fair\", \"Good\", \"Very Good\", \n", |
1396 | | - " \"Premium\", \"Ideal\"])\n", |
1397 | | - " )" |
| 1399 | + "px.histogram(\n", |
| 1400 | + " diamonds, x=\"cut\", color=\"clarity\",\n", |
| 1401 | + " category_orders=dict(cut=[\n", |
| 1402 | + " \"Fair\", \"Good\", \"Very Good\", \n", |
| 1403 | + " \"Premium\", \"Ideal\"])\n", |
| 1404 | + ")" |
1398 | 1405 | ] |
1399 | 1406 | }, |
1400 | 1407 | { |
|
1485 | 1492 | }, |
1486 | 1493 | "outputs": [], |
1487 | 1494 | "source": [ |
1488 | | - "px.histogram(diamonds, x=\"cut\", color=\"clarity\", barmode=\"group\",\n", |
1489 | | - " category_orders=dict(cut=[\n", |
1490 | | - " \"Fair\", \"Good\", \"Very Good\", \n", |
1491 | | - " \"Premium\", \"Ideal\"])\n", |
1492 | | - " )" |
| 1495 | + "px.histogram(\n", |
| 1496 | + " diamonds, x=\"cut\", color=\"clarity\", barmode=\"group\",\n", |
| 1497 | + " category_orders=dict(cut=[\n", |
| 1498 | + " \"Fair\", \"Good\", \"Very Good\", \n", |
| 1499 | + " \"Premium\", \"Ideal\"])\n", |
| 1500 | + ")" |
1493 | 1501 | ] |
1494 | 1502 | }, |
1495 | 1503 | { |
|
1624 | 1632 | ")\n", |
1625 | 1633 | "for d in fig[\"data\"]:\n", |
1626 | 1634 | " d.update({\"fill\": \"tozeroy\"})\n", |
1627 | | - "Image(fig.to_image(format=\"png\", width=900, height=900))" |
| 1635 | + "Image(fig.to_image(format=\"png\", width=750, height=750))" |
1628 | 1636 | ] |
1629 | 1637 | }, |
1630 | 1638 | { |
|
1687 | 1695 | }, |
1688 | 1696 | "outputs": [], |
1689 | 1697 | "source": [ |
1690 | | - "px.line(ts, x=\"date\", y=\"value\")" |
| 1698 | + "px.line(\n", |
| 1699 | + " ts, x=\"date\", y=\"value\"\n", |
| 1700 | + ")" |
1691 | 1701 | ] |
1692 | 1702 | }, |
1693 | 1703 | { |
|
0 commit comments