|
16 | 16 | "from plotnine import *\n", |
17 | 17 | "import numpy as np\n", |
18 | 18 | "\n", |
19 | | - "from plotly import figure_factory\n", |
20 | 19 | "from plotly import graph_objects\n", |
21 | 20 | "import plotly.express as px\n", |
22 | 21 | "from IPython.core.magic import Magics, magics_class, cell_magic\n", |
|
2801 | 2800 | }, |
2802 | 2801 | "outputs": [], |
2803 | 2802 | "source": [ |
2804 | | - "fig = figure_factory.create_distplot(\n", |
2805 | | - " [diamonds[\"depth\"][diamonds[\"cut\"] == c].values \n", |
2806 | | - " for c in diamonds.cut.unique()\n", |
2807 | | - " ],\n", |
2808 | | - " diamonds.cut.unique(),\n", |
2809 | | - " show_hist=False,\n", |
2810 | | - " show_rug=False,\n", |
2811 | | - ")\n", |
2812 | | - "for d in fig[\"data\"]:\n", |
2813 | | - " d.update({\"fill\": \"tozeroy\"})\n", |
| 2803 | + "from scipy.stats import gaussian_kde\n", |
| 2804 | + "\n", |
| 2805 | + "fig = graph_objects.Figure()\n", |
| 2806 | + "for cut in diamonds[\"cut\"].unique():\n", |
| 2807 | + " depth = diamonds.loc[\n", |
| 2808 | + " diamonds[\"cut\"] == cut, \"depth\"]\n", |
| 2809 | + " grid = np.linspace(\n", |
| 2810 | + " depth.min(), depth.max(),\n", |
| 2811 | + " 500, endpoint=False)\n", |
| 2812 | + " fig.add_trace(graph_objects.Scatter(\n", |
| 2813 | + " x=grid, y=gaussian_kde(depth)(grid),\n", |
| 2814 | + " mode=\"lines\", fill=\"tozeroy\",\n", |
| 2815 | + " name=cut))\n", |
2814 | 2816 | "Image(fig.to_image(format=\"png\", width=750, height=750))" |
2815 | 2817 | ] |
2816 | 2818 | }, |
|
0 commit comments