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?

1

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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." Awesome.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.