Add image annotations to bar plots

This solution will work for axes level plots produced with matplotlib, seaborn, and pandas.DataFrame.plot. The main idea would be to separate the problem into small pieces: Get the flag as an array into the script. E.g. def get_flag(name): path = “path/to/flag/{}.png”.format(name) im = plt.imread(path) return im Position an image at a certain position in a … Read more

How does one insert statistical annotations (stars or p-values)

A brace / bracket can be plotted direct with matplotlib.pyplot.plot or matplotlib.axes.Axes.plot, and annotations can be added with matplotlib.pyplot.text or matplotlib.axes.Axes.text. seaborn categorical plots are 0 indexed, whereas box plots, by default, with matplotlib and pandas, start at range(1, N+1), which can be adjusted with the positions parameter. seaborn is a high-level API for matplotlib, … Read more

Color a scatter plot by Column Values

Imports and Data import numpy import pandas import matplotlib.pyplot as plt import seaborn as sns seaborn.set(style=”ticks”) numpy.random.seed(0) N = 37 _genders= [‘Female’, ‘Male’, ‘Non-binary’, ‘No Response’] df = pandas.DataFrame({ ‘Height (cm)’: numpy.random.uniform(low=130, high=200, size=N), ‘Weight (kg)’: numpy.random.uniform(low=30, high=100, size=N), ‘Gender’: numpy.random.choice(_genders, size=N) }) Update August 2021 With seaborn 0.11.0, it’s recommended to use new figure … Read more

How to add additional plots to a seaborn FacetGrid and specify colors

I think you want units in the call to relplot and then add a layer of lineplot using map: import seaborn as sns import pandas as pd fm = sns.load_dataset(‘fmri’).query(“event == ‘stim'”) g = sns.relplot( data=fm, kind=’line’, col=”region”, x=’timepoint’, y=’signal’, units=”subject”, estimator=None, color=”.7″ ) g.data = fm # Hack needed to work around bug on … Read more