How to remove the duplicate legend when overlaying boxplot and stripplot

You can get what handles/labels should exist in the legend before you actually draw the legend itself. You then draw the legend only with the specific ones you want. import matplotlib.pyplot as plt import seaborn as sns import pandas as pd tips = sns.load_dataset(“tips”) sns.stripplot(x=”day”, y=”total_bill”, hue=”smoker”, data=tips, jitter=True, palette=”Set2″, dodge=True, linewidth=1, edgecolor=”gray”) # Get … Read more

How to add hatches to boxplots with sns.boxplot or sns.catplot

Iterate through each subplot / FacetGrid with for ax in g.axes.flat:. ax.patches contains matplotlib.patches.Rectangle and matplotlib.patches.PathPatch, so the correct ones must be used. Caveat: all hues must appear for each group in each Facet, otherwise the patches and hatches will not match. In this case, manual or conditional code will probably be required to correctly … Read more

Subplot for seaborn boxplot

We create the figure with the subplots: f, axes = plt.subplots(1, 2) Where axes is an array with each subplot. Then we tell each plot in which subplot we want them with the argument ax. sns.boxplot( y=”b”, x= “a”, data=df, orient=”v” , ax=axes[0]) sns.boxplot( y=”c”, x= “a”, data=df, orient=”v” , ax=axes[1]) And the result is:

Seaborn load_dataset

load_dataset looks for online csv files on https://github.com/mwaskom/seaborn-data. Here’s the docstring: Load a dataset from the online repository (requires internet). Parameters name : str Name of the dataset (name.csv on https://github.com/mwaskom/seaborn-data). You can obtain list of available datasets using :func:get_dataset_names kws : dict, optional Passed to pandas.read_csv If you want to modify that online dataset … Read more

How to add a number of observations per group and use group mean in ggplot2 boxplot?

Is this anything like what you’re after? With stat_summary, as requested: # function for number of observations give.n <- function(x){ return(c(y = median(x)*1.05, label = length(x))) # experiment with the multiplier to find the perfect position } # function for mean labels mean.n <- function(x){ return(c(y = median(x)*0.97, label = round(mean(x),2))) # experiment with the … Read more