Skip to content

Commit f811043

Browse files
committed
Replace removed Plotly distribution plot helper
1 parent 0b1e130 commit f811043

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

‎Examples.ipynb‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"from plotnine import *\n",
1717
"import numpy as np\n",
1818
"\n",
19-
"from plotly import figure_factory\n",
2019
"from plotly import graph_objects\n",
2120
"import plotly.express as px\n",
2221
"from IPython.core.magic import Magics, magics_class, cell_magic\n",
@@ -2801,16 +2800,19 @@
28012800
},
28022801
"outputs": [],
28032802
"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",
28142816
"Image(fig.to_image(format=\"png\", width=750, height=750))"
28152817
]
28162818
},

0 commit comments

Comments
 (0)