Skip to content

Commit

Permalink
python tutorial for ptitprince 0.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
pog87 committed Sep 3, 2019
1 parent 1639e6e commit 3360e31
Show file tree
Hide file tree
Showing 22 changed files with 52 additions and 24 deletions.
Binary file modified figs/tutorial_python/figureP01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/tutorial_python/figureP02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/tutorial_python/figureP03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/tutorial_python/figureP04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/tutorial_python/figureP05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/tutorial_python/figureP06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/tutorial_python/figureP07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/tutorial_python/figureP08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/tutorial_python/figureP09.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/tutorial_python/figureP10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/tutorial_python/figureP11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/tutorial_python/figureP12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/tutorial_python/figureP13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/tutorial_python/figureP14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/tutorial_python/figureP15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/tutorial_python/figureP16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/tutorial_python/figureP17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/tutorial_python/figureP18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/tutorial_python/figureP19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/tutorial_python/figureP20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ matplotlib
numpy
scipy
seaborn>=0.9
ptitprince==0.1.3
ptitprince==0.1.5
74 changes: 51 additions & 23 deletions tutorial_python/raincloud_tutorial_python.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
"outputs": [],
"source": [
"import pandas as pd\n",
"import ptitprince as pt\n",
"import seaborn as sns\n",
"import os\n",
"import matplotlib.pyplot as plt\n",
"#sns.set(style=\"darkgrid\")\n",
"#sns.set(style=\"whitegrid\")\n",
"#sns.set_style(\"white\")\n",
"sns.set(style=\"whitegrid\",font_scale=2)\n",
"import matplotlib.collections as clt"
"import matplotlib.collections as clt\n",
"\n",
"\n",
"import ptitprince as pt"
]
},
{
Expand Down Expand Up @@ -210,6 +212,7 @@
"#adding color\n",
"pal = \"Set2\"\n",
"f, ax = plt.subplots(figsize=(7, 5))\n",
"\n",
"ax=pt.half_violinplot( x = dx, y = dy, data = df, palette = pal, bw = .2, cut = 0.,\n",
" scale = \"area\", width = .6, inner = None, orient = ort)\n",
"ax=sns.stripplot( x = dx, y = dy, data = df, palette = pal, edgecolor = \"white\",\n",
Expand Down Expand Up @@ -239,8 +242,10 @@
"source": [
"#same thing with a single command: now x **must** be the categorical value\n",
"dx = \"group\"; dy = \"score\"; ort = \"h\"; pal = \"Set2\"; sigma = .2\n",
"ax=pt.RainCloud(x = dx, y = dy, data = df, palette = pal, bw = sigma,\n",
" width_viol = .6, figsize = (7,5), orient = ort)\n",
"f, ax = plt.subplots(figsize=(7, 5))\n",
"\n",
"pt.RainCloud(x = dx, y = dy, data = df, palette = pal, bw = sigma,\n",
" width_viol = .6, ax = ax, orient = ort)\n",
"\n",
"plt.title(\"Figure P7\\n Using the pt.Raincloud function\")\n",
"if savefigs:\n",
Expand All @@ -262,8 +267,10 @@
"source": [
"#moving the rain below the boxplot\n",
"dx = \"group\"; dy = \"score\"; ort = \"h\"; pal = \"Set2\"; sigma = .2\n",
"f, ax = plt.subplots(figsize=(7, 5))\n",
"\n",
"ax=pt.RainCloud(x = dx, y = dy, data = df, palette = pal, bw = sigma,\n",
" width_viol = .6, figsize = (7,5), orient = ort, move = .2)\n",
" width_viol = .6, ax = ax, orient = ort, move = .2)\n",
"\n",
"plt.title(\"Figure P8\\n Rainclouds with Shifted Rain\")\n",
"if savefigs:\n",
Expand All @@ -285,8 +292,10 @@
"source": [
"# Usage with a list/np.array input\n",
"dx = list(df[\"group\"]); dy = list(df[\"score\"])\n",
"f, ax = plt.subplots(figsize=(7, 5))\n",
"\n",
"ax=pt.RainCloud(x = dx, y = dy, palette = pal, bw = sigma,\n",
" width_viol = .6, figsize = (7,5), orient = ort)\n",
" width_viol = .6, ax = ax, orient = ort)\n",
"\n",
"plt.title(\"Figure P9\\n Rainclouds with List/Array Inputs\")\n",
"if savefigs:\n",
Expand All @@ -308,8 +317,10 @@
"source": [
"# Changing orientation\n",
"dx=\"group\"; dy=\"score\"; ort=\"v\"; pal = \"Set2\"; sigma = .2\n",
"f, ax = plt.subplots(figsize=(7, 5))\n",
"\n",
"ax=pt.RainCloud(x = dx, y = dy, data = df, palette = pal, bw = sigma,\n",
" width_viol = .5, figsize = (7,5), orient = ort)\n",
" width_viol = .5, ax = ax, orient = ort)\n",
"\n",
"plt.title(\"Figure P10\\n Flipping your Rainclouds\")\n",
"if savefigs:\n",
Expand All @@ -331,8 +342,10 @@
"source": [
"#changing cloud smoothness\n",
"dx=\"group\"; dy=\"score\"; ort=\"h\"; pal = \"Set2\"; sigma = .05\n",
"f, ax = plt.subplots(figsize=(7, 5))\n",
"\n",
"ax=pt.RainCloud(x = dx, y = dy, data = df, palette = pal, bw = sigma,\n",
" width_viol = .6, figsize = (7,5), orient = ort)\n",
" width_viol = .6, ax = ax, orient = ort)\n",
"\n",
"plt.title(\"Figure P11\\n Customizing Raincloud Smoothness\")\n",
"if savefigs:\n",
Expand All @@ -354,8 +367,10 @@
"source": [
"#adding a red line connecting the groups' mean value (useful for longitudinal data)\n",
"dx=\"group\"; dy=\"score\"; ort=\"h\"; pal = \"Set2\"; sigma = .2\n",
"f, ax = plt.subplots(figsize=(7, 5))\n",
"\n",
"ax=pt.RainCloud(x = dx, y = dy, data = df, palette = pal, bw = sigma,\n",
" width_viol = .6, figsize = (7,5), orient = ort,\\\n",
" width_viol = .6, ax = ax, orient = ort,\n",
" pointplot = True)\n",
"\n",
"plt.title(\"Figure P12\\n Adding Lineplots to Emphasize Factorial Effects\")\n",
Expand All @@ -379,7 +394,7 @@
"# Rainclouds with FacetGrid\n",
"g = sns.FacetGrid(df, col = \"gr2\", height = 6)\n",
"g = g.map_dataframe(pt.RainCloud, x = \"group\", y = \"score\", data = df,\n",
" orient = \"h\", ax = g.axes)\n",
" orient = \"h\")\n",
"\n",
"g.fig.subplots_adjust(top=0.75)\n",
"g.fig.suptitle(\"Figure P13\\n Using FacetGrid for More Complex Designs\", fontsize=26)\n",
Expand All @@ -402,8 +417,10 @@
"source": [
"# Hue Input for Subgroups\n",
"dx=\"group\"; dy=\"score\"; dhue = \"gr2\"; ort=\"h\"; pal = \"Set2\"; sigma = .2\n",
"f, ax = plt.subplots(figsize=(12, 5))\n",
"\n",
"ax=pt.RainCloud(x = dx, y = dy, hue = dhue, data = df, palette = pal, bw = sigma,\n",
" width_viol = .7, figsize = (12,5), orient = ort)\n",
" width_viol = .7, ax = ax, orient = ort)\n",
"\n",
"plt.title(\"Figure P14\\n Rainclouds with Subgroups\")\n",
"if savefigs:\n",
Expand All @@ -424,8 +441,10 @@
"outputs": [],
"source": [
"# Setting alpha level\n",
"f, ax = plt.subplots(figsize=(12, 5))\n",
"\n",
"ax=pt.RainCloud(x = dx, y = dy, hue = dhue, data = df, palette = pal, bw = sigma,\n",
" width_viol = .7, figsize = (12,5), orient = ort , alpha = .65)\n",
" width_viol = .7, ax = ax, orient = ort , alpha = .65)\n",
"\n",
"plt.title(\"Figure P15\\n Adjusting Raincloud Alpha Level\")\n",
"if savefigs:\n",
Expand All @@ -446,8 +465,10 @@
"outputs": [],
"source": [
"#The Doge Flag\n",
"f, ax = plt.subplots(figsize=(12, 5))\n",
"\n",
"ax=pt.RainCloud(x = dx, y = dy, hue = dhue, data = df, palette = pal, bw = sigma,\n",
" width_viol = .7, figsize = (12,5), orient = ort , alpha = .65, dodge = True)\n",
" width_viol = .7, ax = ax, orient = ort , alpha = .65, dodge = True)\n",
"\n",
"plt.title(\"Figure P16\\n The Boxplot Dodge Flag\")\n",
"if savefigs:\n",
Expand All @@ -468,8 +489,9 @@
"outputs": [],
"source": [
"#same, with dodging and line\n",
"f, ax = plt.subplots(figsize=(12, 5))\n",
"ax=pt.RainCloud(x = dx, y = dy, hue = dhue, data = df, palette = pal, bw = sigma, width_viol = .7,\n",
" figsize = (12,5), orient = ort , alpha = .65, dodge = True, pointplot = True)\n",
" ax = ax, orient = ort , alpha = .65, dodge = True, pointplot = True)\n",
"\n",
"plt.title(\"Figure P17\\n Dodged Boxplots with Lineplots\")\n",
"if savefigs:\n",
Expand All @@ -489,9 +511,11 @@
"metadata": {},
"outputs": [],
"source": [
"#moving the rain under the boxplot \n",
"#moving the rain under the boxplot\n",
"f, ax = plt.subplots(figsize=(12, 5))\n",
"\n",
"ax=pt.RainCloud(x = dx, y = dy, hue = dhue, data = df, palette = pal, bw = sigma, width_viol = .7,\n",
" figsize = (12,5), orient = ort , alpha = .65, dodge = True, pointplot = True, move = .2)\n",
" ax = ax, orient = ort , alpha = .65, dodge = True, pointplot = True, move = .2)\n",
"\n",
"plt.title(\"Figure P18\\n Shifting the Rain with the Move Parameter\")\n",
"if savefigs:\n",
Expand Down Expand Up @@ -525,8 +549,10 @@
"source": [
"# Plot the repeated measures data\n",
"dx = \"group\"; dy = \"score\"; dhue = \"timepoint\"; ort = \"h\"; pal = \"Set2\"; sigma = .2\n",
"f, ax = plt.subplots(figsize=(12, 5))\n",
"\n",
"ax=pt.RainCloud(x = dx, y = dy, hue = dhue, data = df_rep, palette = pal, bw = sigma, width_viol = .7,\n",
" figsize = (12,5), orient = ort , alpha = .65, dodge = True, pointplot = True, move = .2)\n",
" ax = ax, orient = ort , alpha = .65, dodge = True, pointplot = True, move = .2)\n",
"\n",
"plt.title(\"Figure P19\\n Repeated Measures Data - Example 1\")\n",
"if savefigs:\n",
Expand All @@ -550,8 +576,10 @@
"source": [
"# Now with the group as hue\n",
"dx = \"timepoint\"; dy = \"score\"; dhue = \"group\"\n",
"f, ax = plt.subplots(figsize=(12, 5))\n",
"\n",
"ax=pt.RainCloud(x = dx, y = dy, hue = dhue, data = df_rep, palette = pal, bw = sigma, width_viol = .7,\n",
" figsize = (12,5), orient = ort , alpha = .65, dodge = True, pointplot = True, move = .2)\n",
" ax = ax, orient = ort , alpha = .65, dodge = True, pointplot = True, move = .2)\n",
"\n",
"plt.title(\"Figure P20\\n Repeated Measures Data - Example 2\")\n",
"if savefigs:\n",
Expand All @@ -568,21 +596,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 2",
"language": "python",
"name": "python3"
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
"pygments_lexer": "ipython2",
"version": "2.7.16"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 3360e31

Please sign in to comment.