0

I would like to present individual data points (NMSE values for a number of experiments in, let's say, two categories) similar to a box plot, and I want to show all individual data points. Assuming the main direction of the data is upside-down, a jittered (or scattered) dot plot is a nice way to slightly move data points sideways to avoid overlapping dots. For a visualization of this idea, check Google Image Search or this article.

I have found and read Adding a scatter of points to a boxplot using matplotlib, but these solution involve adding random noise irrespective of the data, so one has to fine tune parameters and maybe reiterate until one has a nice solution. And then you try to reproduce these a couple of months later ;)

So I would like an automated solution that creates figures such as the ones shown here. Are there solutions to do this with Matplotlib?

bers
  • 4,817
  • 2
  • 40
  • 59
  • Possible duplicate of [How to create swarm plot with matplotlib](https://stackoverflow.com/questions/36153410/how-to-create-swarm-plot-with-matplotlib) – bers Jun 26 '18 at 07:46

1 Answers1

1

You're looking for a "swarmplot", which is nicely implemented in seaborn

import pandas as pd
import seaborn as sns
sns.set(style="whitegrid", palette="muted")

# Load the example iris dataset
iris = sns.load_dataset("iris")

# "Melt" the dataset to "long-form" or "tidy" representation
iris = pd.melt(iris, "species", var_name="measurement")

# Draw a categorical scatterplot to show each observation
sns.swarmplot(x="measurement", y="value", hue="species", data=iris)

enter image description here

Diziet Asahi
  • 38,379
  • 7
  • 60
  • 75
  • Great solution. And for those slightly intimidated by the `DataFrame` format and `pd.melt`, rest assured: "[Input data can be passed in a variety of formats, including (...) Anything accepted by `plt.boxplot`](https://seaborn.pydata.org/generated/seaborn.swarmplot.html)." Awesome. – bers Jun 26 '18 at 07:40