### Install PtitPrince from GitHub Source: https://github.com/pog87/ptitprince/blob/master/README.md Installs the PtitPrince package directly from its GitHub repository. This is useful for installing the latest development version or a specific commit. ```bash pip install git+https://github.com/pog87/PtitPrince ``` -------------------------------- ### Install PtitPrince using pip Source: https://github.com/pog87/ptitprince/blob/master/README.md Installs the PtitPrince package from the Python Package Index (PyPI) using pip. This is the standard method for installing Python packages. ```bash pip install ptitprince ``` -------------------------------- ### Install PtitPrince using conda Source: https://github.com/pog87/ptitprince/blob/master/README.md Installs the PtitPrince package from the conda-forge channel using the conda package manager. This is an alternative installation method, often preferred in scientific computing environments. ```bash conda install -c conda-forge ptitprince ``` -------------------------------- ### Create Raincloud Plots with PtitPrince Source: https://context7.com/pog87/ptitprince/llms.txt Demonstrates the use of the RainCloud function to generate comprehensive plots. Includes examples for basic horizontal layouts, subgrouping with hue, vertical orientation, and component-level styling. ```python import matplotlib.pyplot as plt import pandas as pd import ptitprince as pt df = pd.DataFrame({ 'group': ['Group1']*50 + ['Group2']*50, 'score': [34.3, 40.1, 93.4, 46.2, 47.5] * 10 + [55.2, 62.8, 78.1, 51.3, 49.9] * 10, 'condition': ['high', 'low'] * 50 }) # Basic horizontal raincloud plot f, ax = plt.subplots(figsize=(10, 6)) ax = pt.RainCloud( x='group', y='score', data=df, palette='Set2', bw=0.2, width_viol=0.6, width_box=0.15, orient='h', ax=ax ) plt.show() # Raincloud with hue for subgroups f, ax = plt.subplots(figsize=(12, 6)) ax = pt.RainCloud( x='group', y='score', hue='condition', data=df, palette='Set2', bw=0.2, width_viol=0.7, orient='h', alpha=0.65, dodge=True, pointplot=True, move=0.2, ax=ax ) plt.show() ``` -------------------------------- ### Customized RainCloud Plot with Kwargs (Python) Source: https://github.com/pog87/ptitprince/blob/master/RainCloud_Plot.ipynb This example shows how to create a customized RainCloud plot by passing keyword arguments (kwargs) to control various plot components. It demonstrates disabling outliers, adjusting transparency, and setting edge colors. This feature is available from version 0.2.0. Dependencies include matplotlib and ptitprince. ```python import matplotlib.pyplot as plt import ptitprince as pt # Assuming ddf is a pandas DataFrame with columns "EmotionCondition" and "Sensitivity" # f, ax = plt.subplots(figsize=(12, 11)) pt.RainCloud( data=ddf, x="EmotionCondition", y="Sensitivity", hue="EmotionCondition", ax=ax, box_showfliers=False, rain_alpha=0.4, rain_edgecolor="gray", ) ``` -------------------------------- ### Customize RainCloud Plot Appearance Source: https://context7.com/pog87/ptitprince/llms.txt Provides a comprehensive example of customizing RainCloud plot components including violin smoothness, boxplot dimensions, and rain point styling using prefixed keyword arguments. ```python import matplotlib.pyplot as plt import pandas as pd import ptitprince as pt df = pd.DataFrame({'group': ['A']*40 + ['B']*40, 'score': list(range(20, 60)) + list(range(35, 75))}) f, ax = plt.subplots(figsize=(10, 6)) ax = pt.RainCloud( x='group', y='score', data=df, orient='h', palette='viridis', width_viol=0.7, bw=0.15, cut=0.0, scale='area', offset=0.2, width_box=0.1, jitter=True, point_size=4, move=0.25, alpha=0.8, linewidth=1.5, cloud_inner=None, box_showfliers=True, box_linewidth=1.5, rain_edgecolor='white', rain_linewidth=0.5, ax=ax ) plt.show() ``` -------------------------------- ### Initialize Environment and Load Data Source: https://github.com/pog87/ptitprince/blob/master/RainCloud_Plot.ipynb Sets up the plotting environment with seaborn styles and prepares the dataset using pandas melt for long-format visualization. ```python import matplotlib.pyplot as plt import seaborn as sns import pandas as pd sns.set(style="whitegrid", font_scale=2) df = pd.read_csv("https://data.bris.ac.uk/datasets/112g2vkxomjoo1l26vjmvnlexj/2016.08.14_AnxietyPaper_Data%20Sheet.csv", sep=",") ddf = pd.melt(df, id_vars=["Participant"], value_vars=["AngerUH", "DisgustUH", "FearUH", "HappyUH"], var_name="EmotionCondition", value_name="Sensitivity") ``` -------------------------------- ### Compare Bandwidth Smoothness Source: https://context7.com/pog87/ptitprince/llms.txt Illustrates the effect of the bandwidth parameter on the smoothness of the violin plot component in a RainCloud visualization. ```python fig, axes = plt.subplots(1, 3, figsize=(15, 5)) bandwidths = [0.05, 0.2, 0.5] for ax, bw in zip(axes, bandwidths): pt.RainCloud(x='group', y='score', data=df, palette='Set2', orient='h', bw=bw, ax=ax) ax.set_title(f'Bandwidth = {bw}') plt.show() ``` -------------------------------- ### Import PtitPrince Package Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Appends the PtitPrince package directory to the system path and imports the PtitPrince module, aliased as 'pt'. This makes the Raincloud plotting functions available. ```python import sys sys.path.append("../ptitprince/") import PtitPrince as pt ``` -------------------------------- ### Create Basic Raincloud Plot (Half Violin) Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Creates a basic Raincloud plot by first plotting a half-violin distribution using PtitPrince's `half_violinplot`. It configures the plot orientation, color palette, and other aesthetic parameters. ```python # plotting the clouds f, ax = plt.subplots(figsize=(7, 5)) dy = "group" dx = "score" ort = "h" pal = sns.color_palette(n_colors=1) ax = pt.half_violinplot( x=dx, y=dy, data=df, palette=pal, bw=0.2, cut=0.0, scale="area", width=0.6, inner=None, orient=ort, ) plt.title("Figure P2\n Basic Rainclouds") if savefigs: plt.savefig("../figs/tutorial_python/figureP02.png", bbox_inches="tight") ``` -------------------------------- ### Load and Display Data Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Loads data from a CSV file named 'simdat.csv' into a pandas DataFrame and displays the first few rows using the .head() method. This is the initial step for data visualization. ```python df = pd.read_csv("simdat.csv", sep=",") df.head() ``` -------------------------------- ### Rainclouds with FacetGrid (Python) Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Demonstrates how to use Seaborn's FacetGrid to create multiple raincloud plots, each representing a different category or factor level. This approach is effective for visualizing complex datasets with multiple subgroups. ```python g = sns.FacetGrid(df, col="gr2", height=6) g = g.map_dataframe(pt.RainCloud, x="group", y="score", data=df, orient="h", hue="group") for ax in g.axes.flat: ax.set_xlabel("") ax.set_ylabel("") g.fig.subplots_adjust(top=0.75) g.fig.suptitle("Figure P13\n Using FacetGrid for More Complex Designs", fontsize=26) if savefigs: plt.savefig("../figs/tutorial_python/figureP13.png", bbox_inches="tight") ``` -------------------------------- ### Generate Half-Violin Plots Source: https://context7.com/pog87/ptitprince/llms.txt Shows how to create standalone half-violin plots using the half_violinplot function. This is useful for building custom visualizations or isolating the density estimation component. ```python import matplotlib.pyplot as plt import pandas as pd import ptitprince as pt df = pd.DataFrame({ 'group': ['A']*30 + ['B']*30 + ['C']*30, 'value': [20, 25, 30, 35, 40] * 6 + [40, 45, 50, 55, 60] * 6 + [15, 20, 25, 30, 35] * 6 }) f, ax = plt.subplots(figsize=(8, 5)) ax = pt.half_violinplot( x='value', y='group', data=df, palette='Set2', bw=0.2, cut=0.0, scale='area', width=0.6, inner=None, orient='h', offset=0.15 ) plt.show() ``` -------------------------------- ### FacetGrid Integration for Multi-Panel Plots Source: https://context7.com/pog87/ptitprince/llms.txt Demonstrates how to map the pt.RainCloud function onto a seaborn FacetGrid to create complex, multi-panel visualizations for factorial experimental designs. ```python g = sns.FacetGrid(df, col='condition', height=6) g = g.map_dataframe(pt.RainCloud, x='group', y='score', data=df, orient='h', palette='Set2', hue='group') plt.show() g = sns.FacetGrid(df, col='condition', row='timepoint', height=4) g = g.map_dataframe(pt.RainCloud, x='group', y='score', orient='h', palette='Set2') plt.tight_layout() plt.show() ``` -------------------------------- ### Basic RainCloud Plot Generation (Python) Source: https://github.com/pog87/ptitprince/blob/master/RainCloud_Plot.ipynb This snippet demonstrates how to create a basic RainCloud plot using the ptitprince library. It takes a pandas DataFrame as input and visualizes the distribution of a numerical variable ('A') across different categories ('Category'). Dependencies include matplotlib and ptitprince. ```python import matplotlib.pyplot as plt import ptitprince as pt f, ax = plt.subplots(figsize=(12, 11)) pt.RainCloud(data=df_rand, x="Category", y="A", hue="Category", orient="h", bw=0.1) ``` -------------------------------- ### Generate Basic Raincloud Plot with Subgroups Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Creates a standard raincloud plot using the PtitPrince library. It maps categorical variables to hue and orientation to visualize data distribution. ```python f, ax = plt.subplots(figsize=(12, 5)) ax = pt.RainCloud(x=dx, y=dy, hue=dhue, data=df, palette=pal, bw=sigma, width_viol=0.7, ax=ax, orient=ort) plt.title("Figure P14\n Rainclouds with Subgroups") ``` -------------------------------- ### Half-Violin Plot with Split Hue Source: https://context7.com/pog87/ptitprince/llms.txt Uses ptitprince's half_violinplot to visualize distributions, utilizing the split parameter to compare two hue levels within a single category. ```python f, ax = plt.subplots(figsize=(8, 5)) ax = pt.half_violinplot(x='value', y='category', hue='hue', data=df_split, palette='Set1', bw=0.3, orient='h', split=True, inner='quartiles') plt.title("Split Half Violin") plt.show() ``` -------------------------------- ### Generate Raincloud Plot with One-Liner Source: https://github.com/pog87/ptitprince/blob/master/RainCloud_Plot.ipynb Uses the simplified RainCloud method from the ptitprince library to generate plots with minimal code. ```python # Vertical f, ax = plt.subplots(figsize=(12, 11)) pt.RainCloud(data=ddf, x="EmotionCondition", y="Sensitivity", hue="EmotionCondition", ax=ax) # Horizontal f, ax = plt.subplots(figsize=(12, 11)) pt.RainCloud(data=ddf, x="EmotionCondition", y="Sensitivity", hue="EmotionCondition", orient="h", ax=ax) ``` -------------------------------- ### Configure Figure Saving Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Sets a boolean flag to control whether figures are saved and defines the directory for saving figures. It includes logic to create the directory if it does not exist. ```python savefigs = True figs_dir = "../figs/tutorial_python" if savefigs: # Make the figures folder if it doesn't yet exist if not os.path.isdir("../figs/tutorial_python"): os.makedirs("../figs/tutorial_python") ``` -------------------------------- ### Create Repeated Measures RainCloud Plots Source: https://context7.com/pog87/ptitprince/llms.txt Demonstrates how to visualize repeated measures data using RainCloud plots. It shows two configurations: grouping by timepoint within groups and grouping by group within timepoints, utilizing the dodge and pointplot parameters. ```python import matplotlib.pyplot as plt import ptitprince as pt # Repeated measures plot with timepoint as hue f, ax = plt.subplots(figsize=(12, 6)) ax = pt.RainCloud( x='group', y='score', hue='timepoint', data=df_rep, palette='Set2', bw=0.2, width_viol=0.7, orient='h', alpha=0.65, dodge=True, pointplot=True, move=0.2, ax=ax ) plt.show() # Alternative: group as hue within timepoints f, ax = plt.subplots(figsize=(12, 6)) ax = pt.RainCloud( x='timepoint', y='score', hue='group', data=df_rep, palette='Set1', bw=0.2, width_viol=0.7, orient='h', alpha=0.65, dodge=True, pointplot=True, move=0.2, ax=ax ) plt.show() ``` -------------------------------- ### Customizing Raincloud Smoothness (Python) Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Illustrates how to adjust the smoothness of the probability distribution curve in a raincloud plot by modifying the 'sigma' parameter. A smaller sigma value results in a sharper, less smooth curve, while a larger value creates a smoother curve. ```python dx = "group" dy = "score" ort = "h" pal = "Set2" sigma = 0.05 f, ax = plt.subplots(figsize=(7, 5)) ax = pt.RainCloud( x=dx, y=dy, data=df, palette=pal, hue="group", bw=sigma, width_viol=0.6, ax=ax, orient=ort ) plt.title("Figure P11\n Customizing Raincloud Smoothness") if savefigs: plt.savefig("../figs/tutorial_python/figureP11.png", bbox_inches="tight") ``` -------------------------------- ### Import Libraries and Set Seaborn Style Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Imports necessary libraries like os, matplotlib, pandas, and seaborn. It also sets the visual style for Seaborn plots to 'whitegrid' with an increased font scale. ```python import os import matplotlib.pyplot as plt import pandas as pd import seaborn as sns sns.set(style="whitegrid", font_scale=2) ``` -------------------------------- ### Shift Raincloud Components with Move Parameter Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Demonstrates using the 'move' parameter in the pt.RainCloud function to shift the rain (stripplot) relative to the boxplot for better visual clarity. ```python ax = pt.RainCloud(x=dx, y=dy, data=df, palette=pal, hue="group", bw=sigma, width_viol=0.6, ax=ax, orient=ort, move=0.2) plt.title("Figure P8\n Rainclouds with Shifted Rain") ``` -------------------------------- ### Manual Raincloud Plot Construction Source: https://context7.com/pog87/ptitprince/llms.txt Demonstrates how to manually combine seaborn stripplot and boxplot components to create a raincloud plot. This approach offers granular control over the visual layers. ```python ax = sns.stripplot(x='value', y='group', data=df, palette=pal, hue='group', edgecolor='white', size=3, jitter=True, zorder=0, orient='h') ax = sns.boxplot(x='value', y='group', data=df, color='black', width=0.15, zorder=10, showcaps=True, boxprops={'facecolor': 'none', 'zorder': 10}, whiskerprops={'linewidth': 2, 'zorder': 10}, saturation=1, orient='h') plt.title("Manual Raincloud Construction") plt.show() ``` -------------------------------- ### Generate Repeated Measures Raincloud Plot (Python) Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Generates a raincloud plot for repeated measures data using PtitPrince. It visualizes the distribution of 'score' across 'timepoint' for different 'group's. The plot is configured with specific aesthetics and can be saved to a file. ```Python dx = "group" dy = "score" dhue = "timepoint" ort = "h" pal = "Set2" sigma = 0.2 f, ax = plt.subplots(figsize=(12, 5)) ax = pt.RainCloud( x=dx, y=dy, hue=dhue, data=df_rep, palette=pal, bw=sigma, width_viol=0.7, ax=ax, orient=ort, alpha=0.65, dodge=True, pointplot=True, move=0.2, ) plt.title("Figure P19\n Repeated Measures Data - Example 1") if savefigs: plt.savefig("../figs/tutorial_python/figureP19.png", bbox_inches="tight") ``` -------------------------------- ### Create Vertical Raincloud Plot Source: https://github.com/pog87/ptitprince/blob/master/RainCloud_Plot.ipynb Generates a vertical Raincloud plot by combining half-violin, strip, and box plots using the ptitprince library. ```python from ptitprince import PtitPrince as pt f, ax = plt.subplots(figsize=(12, 11)) dy = "Sensitivity" dx = "EmotionCondition" ort = "v" ax = pt.half_violinplot(data=ddf, palette="Set2", bw=0.2, linewidth=1, cut=0.0, scale="area", width=0.8, inner=None, orient=ort, x=dx, y=dy) ax = sns.stripplot(data=ddf, palette="Set2", hue="EmotionCondition", edgecolor="white", size=2, orient=ort, x=dx, y=dy, jitter=True, zorder=0) ax = sns.boxplot(data=ddf, color="black", orient=ort, width=0.15, x=dx, y=dy, zorder=10, showcaps=True, boxprops={"facecolor": "none", "zorder": 10}, showfliers=True, whiskerprops={"linewidth": 2, "zorder": 10}, saturation=1) sns.despine(left=True) ``` -------------------------------- ### Enhanced Stripplot with Move and Dodge Source: https://context7.com/pog87/ptitprince/llms.txt Showcases the pt.stripplot wrapper, which adds a 'move' parameter for precise point positioning and supports 'dodge' for separating hue subgroups. ```python ax = pt.stripplot(x='score', y='group', data=df, palette='Set2', jitter=True, orient='h', size=5, edgecolor='white', linewidth=0.5, move=0.2) plt.title("Stripplot with Move Parameter") plt.show() ax = pt.stripplot(x='score', y='group', hue='condition', data=df_hue, palette='Set2', jitter=True, orient='h', dodge=True, width=0.8, size=4) plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left') plt.title("Dodged Stripplot") plt.show() ``` -------------------------------- ### Generate Repeated Measures Raincloud Plot with Swapped Hue (Python) Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Generates a raincloud plot for repeated measures data, this time swapping the 'group' and 'timepoint' variables for the hue and x-axis respectively. This allows for a different perspective on the data distribution. The plot is configured with specific aesthetics and can be saved. ```Python # Now with the group as hue dx = "timepoint" dy = "score" dhue = "group" f, ax = plt.subplots(figsize=(12, 5)) ax = pt.RainCloud( x=dx, y=dy, hue=dhue, data=df_rep, palette=pal, bw=sigma, width_viol=0.7, ax=ax, orient=ort, alpha=0.65, dodge=True, pointplot=True, move=0.2, ) plt.title("Figure P20\n Repeated Measures Data - Example 2") if savefigs: plt.savefig("../figs/tutorial_python/figureP20.png", bbox_inches="tight") ``` -------------------------------- ### Generate Automated Raincloud Plot Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Uses the pt.RainCloud convenience function to generate a complete raincloud plot with a single command. This simplifies the syntax compared to manual layering. ```python pt.RainCloud(x=dx, y=dy, data=df, palette=pal, hue="group", bw=sigma, width_viol=0.6, ax=ax, orient=ort) plt.title("Figure P7\n Using the pt.Raincloud function") ``` -------------------------------- ### Generate Mixed Gaussian Data for RainCloud Plot (Python) Source: https://github.com/pog87/ptitprince/blob/master/RainCloud_Plot.ipynb This code generates a synthetic dataset with two mixed Gaussian distributions and a categorical variable. It prepares the data in a pandas DataFrame suitable for plotting with pt.RainCloud. Dependencies include numpy and pandas. ```python import numpy as np import pandas as pd x = 3.5 + 2 * np.random.randn(1000, 2) x1 = -3.5 + 2 * np.random.randn(1000, 2) x = np.concatenate((x, x1), axis=0) x_cat = np.random.randint(0, 4, size=(2000, 1)) x = np.concatenate((x_cat, x), axis=1) df_rand = pd.DataFrame(x, columns=["Category", "A", "B"]) ``` -------------------------------- ### Flipping Raincloud Orientation (Python) Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Demonstrates how to change the orientation of a raincloud plot from horizontal to vertical (or vice-versa) using the 'orient' flag in the pt.RainCloud function. This is useful for adapting plots to different data structures or visual preferences. ```python dx = "group" dy = "score" ort = "v" pal = "Set2" sigma = 0.2 f, ax = plt.subplots(figsize=(7, 5)) ax = pt.RainCloud( x=dx, y=dy, data=df, palette=pal, hue="group", bw=sigma, width_viol=0.5, ax=ax, orient=ort ) plt.title("Figure P10\n Flipping your Rainclouds") if savefigs: plt.savefig("../figs/tutorial_python/figureP10.png", bbox_inches="tight") ``` -------------------------------- ### Load Repeated Measures Data Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Reads a CSV file containing repeated measures data and prepares the columns for plotting. ```python df_rep = pd.read_csv("repeated_measures_data.csv", sep=",") df_rep.columns = ["score", "timepoint", "group"] df_rep.head() ``` -------------------------------- ### Add Pointplot for Interaction Effects Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Integrates a line plot (pointplot) into the raincloud visualization to highlight mean values and interaction effects between groups. ```python f, ax = plt.subplots(figsize=(12, 5)) ax = pt.RainCloud(x=dx, y=dy, hue=dhue, data=df, palette=pal, bw=sigma, width_viol=0.7, ax=ax, orient=ort, alpha=0.65, dodge=True, pointplot=True) plt.title("Figure P17\n Dodged Boxplots with Lineplots") ``` -------------------------------- ### Create Raincloud Plot with Jittered Data Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Combines a half-violin plot with a jittered stripplot to show data distribution and individual points. Requires the ptitprince and seaborn libraries. ```python f, ax = plt.subplots(figsize=(7, 5)) ax = pt.half_violinplot(x=dx, y=dy, data=df, palette=pal, bw=0.2, cut=0.0, scale="area", width=0.6, inner=None, orient=ort) ax = sns.stripplot(x=dx, y=dy, data=df, palette=pal, hue="group", edgecolor="white", size=3, jitter=True, zorder=0, orient=ort) plt.title("Figure P4\n Raincloud with Jittered Data") ``` -------------------------------- ### Create Raincloud Plot with Data Points (No Jitter) Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Enhances the half-violin plot by adding individual data points using Seaborn's stripplot. This 'rain' layer illustrates the distribution and potential outliers more clearly. Jitter is set to 0 for precise point placement. ```python # adding the rain f, ax = plt.subplots(figsize=(7, 5)) ax = pt.half_violinplot( x=dx, y=dy, data=df, palette=pal, bw=0.2, cut=0.0, scale="area", width=0.6, inner=None, orient=ort, ) ax = sns.stripplot( x=dx, y=dy, data=df, palette=pal, hue="group", edgecolor="white", size=3, jitter=0, zorder=0, orient=ort, ) plt.title("Figure P3\n Raincloud Without Jitter") if savefigs: plt.savefig("../figs/tutorial_python/figureP03.png", bbox_inches="tight") ``` -------------------------------- ### Create Horizontal Raincloud Plot Source: https://github.com/pog87/ptitprince/blob/master/RainCloud_Plot.ipynb Generates a horizontal Raincloud plot by configuring the orientation parameter to 'h'. ```python f, ax = plt.subplots(figsize=(12, 11)) dx = "Sensitivity" dy = "EmotionCondition" ort = "h" ax = pt.half_violinplot(data=ddf, palette="Set2", bw=0.2, linewidth=1, cut=0.0, scale="area", width=0.8, inner=None, orient=ort, x=dx, y=dy) ax = sns.stripplot(data=ddf, palette="Set2", hue="EmotionCondition", edgecolor="white", size=2, orient=ort, x=dx, y=dy, jitter=True, zorder=0) ax = sns.boxplot(data=ddf, color="black", orient=ort, width=0.15, x=dx, y=dy, zorder=10, showcaps=True, boxprops={"facecolor": "none", "zorder": 10}, showfliers=True, whiskerprops={"linewidth": 2, "zorder": 10}, saturation=1) sns.despine(left=True) ``` -------------------------------- ### Adding Pointplots to Rainclouds (Python) Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Shows how to add a pointplot to a raincloud plot by setting the 'pointplot' flag to True. This feature connects the mean values of different groups with a line, which is particularly useful for visualizing longitudinal or factorial data. ```python dx = "group" dy = "score" ort = "h" pal = "Set2" sigma = 0.2 f, ax = plt.subplots(figsize=(7, 5)) ax = pt.RainCloud( x=dx, y=dy, data=df, palette=pal, hue="group", bw=sigma, width_viol=0.6, ax=ax, orient=ort, pointplot=True, ) plt.title("Figure P12\n Adding Lineplots to Emphasize Factorial Effects") if savefigs: plt.savefig("../figs/tutorial_python/figureP12.png", bbox_inches="tight") ``` -------------------------------- ### Raincloud Plot with List/Array Input (Python) Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Generates a raincloud plot using lists or numpy arrays as input for x and y variables. It utilizes the pt.RainCloud function from the PtitPrince library, with dependencies on matplotlib and pandas. ```python dx = list(df["group"]) dy = list(df["score"]) f, ax = plt.subplots(figsize=(7, 5)) ax = pt.RainCloud(x=dx, y=dy, palette=pal, bw=sigma, width_viol=0.6, ax=ax, orient=ort) plt.title("Figure P9\n Rainclouds with List/Array Inputs") if savefigs: plt.savefig("../figs/tutorial_python/figureP09.png", bbox_inches="tight") ``` -------------------------------- ### Shift Data Points with Move Parameter Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Adjusts the position of individual observations relative to the boxplots using the move parameter to reduce visual clutter. ```python f, ax = plt.subplots(figsize=(12, 5)) ax = pt.RainCloud(x=dx, y=dy, hue=dhue, data=df, palette=pal, bw=sigma, width_viol=0.7, ax=ax, orient=ort, alpha=0.65, dodge=True, pointplot=True, move=0.2) plt.title("Figure P18\n Shifting the Rain with the Move Parameter") ``` -------------------------------- ### Create Bar Plot Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Generates a bar plot showing the mean 'score' for each 'group' using Seaborn's barplot function. It sets the figure size and adds a title. The plot is saved if 'savefigs' is True. ```python f, ax = plt.subplots(figsize=(7, 7)) sns.barplot(x="group", y="score", data=df, capsize=0.1) plt.title("Figure P1\n Bar Plot") if savefigs: plt.savefig("../figs/tutorial_python/figureP01.png", bbox_inches="tight") ``` -------------------------------- ### Add Boxplot to Raincloud for Statistical Summary Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Enhances the raincloud plot by adding a boxplot to display median, quartiles, and outliers clearly. This helps in identifying statistical differences between groups. ```python ax = sns.boxplot(x=dx, y=dy, data=df, color="black", width=0.15, zorder=10, showfliers=True, boxprops={"facecolor": "none", "zorder": 10}, orient=ort) plt.title("Figure P5\n Raincloud with Boxplot") ``` -------------------------------- ### Export Figure Function Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Defines a utility function to save a matplotlib axis object to a file if the 'savefigs' flag is enabled. It takes the axis, text, and filename as input. ```python def export_fig(axis, text, fname): if savefigs: axis.text() axis.savefig(fname, bbox_inches="tight") ``` -------------------------------- ### Enable Dodge for Boxplots Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Uses the dodge parameter to prevent boxplots from overlapping. This improves readability when multiple subgroups are present. ```python f, ax = plt.subplots(figsize=(12, 5)) ax = pt.RainCloud(x=dx, y=dy, hue=dhue, data=df, palette=pal, bw=sigma, width_viol=0.7, ax=ax, orient=ort, alpha=0.65, dodge=True) plt.title("Figure P16\n The Boxplot Dodge Flag") ``` -------------------------------- ### Adjust Raincloud Transparency Source: https://github.com/pog87/ptitprince/blob/master/tutorial_python/raincloud_tutorial_python.ipynb Modifies the visual appearance of the raincloud plot by setting the alpha parameter. This controls the opacity of the plot elements. ```python f, ax = plt.subplots(figsize=(12, 5)) ax = pt.RainCloud(x=dx, y=dy, hue=dhue, data=df, palette=pal, bw=sigma, width_viol=0.7, ax=ax, orient=ort, alpha=0.65) plt.title("Figure P15\n Adjusting Raincloud Alpha Level") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.