From 1bb5a4c8f0e610ee73fe7e547aa548e9a112c995 Mon Sep 17 00:00:00 2001 From: Kully Date: Thu, 13 Sep 2018 10:21:40 -0400 Subject: [PATCH 1/2] started joyplot nb --- .../python/statistical/joyplot/joyplot.ipynb | 296 ++++++++++++++++++ 1 file changed, 296 insertions(+) create mode 100644 _posts/python/statistical/joyplot/joyplot.ipynb diff --git a/_posts/python/statistical/joyplot/joyplot.ipynb b/_posts/python/statistical/joyplot/joyplot.ipynb new file mode 100644 index 000000000000..728901391518 --- /dev/null +++ b/_posts/python/statistical/joyplot/joyplot.ipynb @@ -0,0 +1,296 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### New to Plotly?\n", + "Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/).\n", + "
You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/#start-plotting-online).\n", + "
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Version Check\n", + "Plotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'3.2.0'" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly\n", + "plotly.__version__" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Joy Plots" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.graph_objs as go\n", + "\n", + "import pandas as pd\n", + "\n", + "df = pd.read_csv(\"https://raw.githubusercontent.com/plotly/datasets/master/violin_data.csv\")\n", + "\n", + "fig = {\n", + " \"data\": [{\n", + " \"type\": 'violin',\n", + " \"y\": df['total_bill'],\n", + " \"box\": {\n", + " \"visible\": False\n", + " },\n", + " \"line\": {\n", + " \"color\": 'black'\n", + " },\n", + " \"meanline\": {\n", + " \"visible\": False\n", + " },\n", + " \"fillcolor\": '#8dd3c7',\n", + " \"opacity\": 1,\n", + " \"x0\": 'Total Bill'\n", + " }],\n", + " \"layout\" : {\n", + " \"title\": \"\",\n", + " \"yaxis\": {\n", + " \"zeroline\": False,\n", + " }\n", + " }\n", + "}\n", + "\n", + "py.iplot(fig, filename='violin/basic', validate=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'data': [{'box': {'visible': False},\n", + " 'fillcolor': '#8dd3c7',\n", + " 'line': {'color': 'black'},\n", + " 'meanline': {'visible': False},\n", + " 'opacity': 1,\n", + " 'type': 'violin',\n", + " 'x0': 'Total Bill',\n", + " 'y': 0 16.99\n", + " 1 10.34\n", + " 2 21.01\n", + " 3 23.68\n", + " 4 24.59\n", + " 5 25.29\n", + " 6 8.77\n", + " 7 26.88\n", + " 8 15.04\n", + " 9 14.78\n", + " 10 10.27\n", + " 11 35.26\n", + " 12 15.42\n", + " 13 18.43\n", + " 14 14.83\n", + " 15 21.58\n", + " 16 10.33\n", + " 17 16.29\n", + " 18 16.97\n", + " 19 20.65\n", + " 20 17.92\n", + " 21 20.29\n", + " 22 15.77\n", + " 23 39.42\n", + " 24 19.82\n", + " 25 17.81\n", + " 26 13.37\n", + " 27 12.69\n", + " 28 21.70\n", + " 29 19.65\n", + " ... \n", + " 214 28.17\n", + " 215 12.90\n", + " 216 28.15\n", + " 217 11.59\n", + " 218 7.74\n", + " 219 30.14\n", + " 220 12.16\n", + " 221 13.42\n", + " 222 8.58\n", + " 223 15.98\n", + " 224 13.42\n", + " 225 16.27\n", + " 226 10.09\n", + " 227 20.45\n", + " 228 13.28\n", + " 229 22.12\n", + " 230 24.01\n", + " 231 15.69\n", + " 232 11.61\n", + " 233 10.77\n", + " 234 15.53\n", + " 235 10.07\n", + " 236 12.60\n", + " 237 32.83\n", + " 238 35.83\n", + " 239 29.03\n", + " 240 27.18\n", + " 241 22.67\n", + " 242 17.82\n", + " 243 18.78\n", + " Name: total_bill, Length: 244, dtype: float64}],\n", + " 'layout': {'title': '', 'yaxis': {'zeroline': False}}}" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fig" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Reference\n", + "See https://plot.ly/python/reference/#violin for more information and chart attribute options!" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting git+https://github.com/plotly/publisher.git\n", + " Cloning https://github.com/plotly/publisher.git to c:\\users\\branden\\appdata\\local\\temp\\pip-5beb6u-build\n", + "Installing collected packages: publisher\n", + " Found existing installation: publisher 0.11\n", + " Uninstalling publisher-0.11:\n", + " Successfully uninstalled publisher-0.11\n", + " Running setup.py install for publisher: started\n", + " Running setup.py install for publisher: finished with status 'done'\n", + "Successfully installed publisher-0.11\n" + ] + } + ], + "source": [ + "from IPython.display import display, HTML\n", + "\n", + "display(HTML(''))\n", + "display(HTML(''))\n", + "\n", + "! pip install git+https://github.com/plotly/publisher.git --upgrade\n", + "import publisher\n", + "publisher.publish(\n", + " 'joyplot.ipynb', 'python/joy-plots/', 'Joy Plots',\n", + " 'How to make joy plots and ridgeline plots in Python with Plotly.',\n", + " title = 'Joy Plots | Plotly',\n", + " has_thumbnail='true',\n", + " thumbnail='thumbnail/joyplot.jpg',\n", + " language='python', \n", + " display_as='statistical', \n", + " order=12.1, #ipynb='~notebook_demo/201'\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "anaconda-cloud": {}, + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.12" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From ab10f37ba6c722b03561e11b18240483b1c9782f Mon Sep 17 00:00:00 2001 From: Kully Date: Fri, 14 Sep 2018 11:53:37 -0400 Subject: [PATCH 2/2] add a notebook - WIP --- .../python/statistical/joyplot/joyplot.ipynb | 160 +++++------------- 1 file changed, 46 insertions(+), 114 deletions(-) diff --git a/_posts/python/statistical/joyplot/joyplot.ipynb b/_posts/python/statistical/joyplot/joyplot.ipynb index 728901391518..90f9c3f95a89 100644 --- a/_posts/python/statistical/joyplot/joyplot.ipynb +++ b/_posts/python/statistical/joyplot/joyplot.ipynb @@ -48,19 +48,21 @@ }, { "cell_type": "code", - "execution_count": 11, - "metadata": {}, + "execution_count": 2, + "metadata": { + "scrolled": false + }, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 11, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -73,122 +75,52 @@ "\n", "df = pd.read_csv(\"https://raw.githubusercontent.com/plotly/datasets/master/violin_data.csv\")\n", "\n", - "fig = {\n", - " \"data\": [{\n", - " \"type\": 'violin',\n", - " \"y\": df['total_bill'],\n", - " \"box\": {\n", - " \"visible\": False\n", - " },\n", - " \"line\": {\n", - " \"color\": 'black'\n", - " },\n", - " \"meanline\": {\n", - " \"visible\": False\n", - " },\n", - " \"fillcolor\": '#8dd3c7',\n", - " \"opacity\": 1,\n", - " \"x0\": 'Total Bill'\n", - " }],\n", - " \"layout\" : {\n", - " \"title\": \"\",\n", - " \"yaxis\": {\n", - " \"zeroline\": False,\n", - " }\n", - " }\n", - "}\n", + "trace1 = dict(\n", + " orientation='h',\n", + " type='violin',\n", + " x=list(df['total_bill'] + 4),\n", + " y0=1,\n", + " box=dict(visible=False),\n", + " line=dict(width=0),\n", + " meanline=dict(visible=False),\n", + " fillcolor='#c78dd3',\n", + " opacity=0.8,\n", + " points=False,\n", + " side='positive',\n", + ")\n", + "\n", + "trace2 = dict(\n", + " orientation='h',\n", + " type='violin',\n", + " x=list(df['total_bill'] + 4),\n", + " y0=0.1,\n", + " box=dict(visible=False),\n", + " line=dict(width=0),\n", + " meanline=dict(visible=False),\n", + " fillcolor='#8dd3c7',\n", + " opacity=0.8,\n", + " points=False,\n", + " side='positive',\n", + ")\n", "\n", - "py.iplot(fig, filename='violin/basic', validate=False)" + "fig = dict(\n", + " data=[trace1, trace2,],\n", + " layout=dict(\n", + " title='',\n", + " yaxis=dict(zeroline=False),\n", + " showlegend=False\n", + " )\n", + ")\n", + "\n", + "py.iplot(fig, filename='violin-for-joyplot')" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'data': [{'box': {'visible': False},\n", - " 'fillcolor': '#8dd3c7',\n", - " 'line': {'color': 'black'},\n", - " 'meanline': {'visible': False},\n", - " 'opacity': 1,\n", - " 'type': 'violin',\n", - " 'x0': 'Total Bill',\n", - " 'y': 0 16.99\n", - " 1 10.34\n", - " 2 21.01\n", - " 3 23.68\n", - " 4 24.59\n", - " 5 25.29\n", - " 6 8.77\n", - " 7 26.88\n", - " 8 15.04\n", - " 9 14.78\n", - " 10 10.27\n", - " 11 35.26\n", - " 12 15.42\n", - " 13 18.43\n", - " 14 14.83\n", - " 15 21.58\n", - " 16 10.33\n", - " 17 16.29\n", - " 18 16.97\n", - " 19 20.65\n", - " 20 17.92\n", - " 21 20.29\n", - " 22 15.77\n", - " 23 39.42\n", - " 24 19.82\n", - " 25 17.81\n", - " 26 13.37\n", - " 27 12.69\n", - " 28 21.70\n", - " 29 19.65\n", - " ... \n", - " 214 28.17\n", - " 215 12.90\n", - " 216 28.15\n", - " 217 11.59\n", - " 218 7.74\n", - " 219 30.14\n", - " 220 12.16\n", - " 221 13.42\n", - " 222 8.58\n", - " 223 15.98\n", - " 224 13.42\n", - " 225 16.27\n", - " 226 10.09\n", - " 227 20.45\n", - " 228 13.28\n", - " 229 22.12\n", - " 230 24.01\n", - " 231 15.69\n", - " 232 11.61\n", - " 233 10.77\n", - " 234 15.53\n", - " 235 10.07\n", - " 236 12.60\n", - " 237 32.83\n", - " 238 35.83\n", - " 239 29.03\n", - " 240 27.18\n", - " 241 22.67\n", - " 242 17.82\n", - " 243 18.78\n", - " Name: total_bill, Length: 244, dtype: float64}],\n", - " 'layout': {'title': '', 'yaxis': {'zeroline': False}}}" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "fig" - ] + "outputs": [], + "source": [] }, { "cell_type": "markdown",