Questions tagged [swarmplot]

A swarm plot (also known as a "beeswarm plot") is a type of data visualization that presents a categorical scatterplot with non-overlapping points.

Description

A swarm plot (also known as a "beeswarm plot") is a type of data visualization that presents a categorical scatterplot with non-overlapping points. It can also be thought of as a variant of a , but with non-overlapping points.

This method of presentation can be helpful if you wish to plot a data distribution while retaining all of the individual data points, especially if many of your data points are concentrated within a narrow range. However, it is not recommended to use beeswarm plots when there are many data points, as the "swarming" can create visual artifacts.

Tools for producing swarm plots exist for programming languages/packages such as , , and . This tag should be used for any questions involving the formatting and/or implementation of these plots.

Implementations

Seaborn, for Python

The beeswarm package for R

Additional Resources

  • A blog post on swarm plots.
  • A data science blog post with advice on when and how to use swarm plots.
  • Examples of swarm plots made using D3
72 questions
63
votes
7 answers

Matplotlib: avoiding overlapping datapoints in a "scatter/dot/beeswarm" plot

When drawing a dot plot using matplotlib, I would like to offset overlapping datapoints to keep them all visible. For example, if I have: CategoryA: 0,0,3,0,5 CategoryB: 5,10,5,5,10 I want each of the CategoryA "0" datapoints to be set side by…
iayork
  • 6,420
  • 8
  • 44
  • 49
13
votes
3 answers

How to create a swarm plot with matplotlib

I know the question is not very informative.. but as I do not know the name of his type of plot, I can not be more informative.. [EDIT] I changed the title, and now it is more informative...
Oren
  • 4,711
  • 4
  • 37
  • 63
11
votes
3 answers

How can box plot be overlaid on top of swarm plot in Seaborn?

I am trying to plot swarm plots and box plots together using matplotlib and Seaborn. I found how to plot them together but the box plot appears underneath the swarm plot. The problem with this is that the swarm plot points drown out the box plot and…
adin
  • 783
  • 3
  • 13
  • 27
9
votes
3 answers

How to add a mean line to a seaborn stripplot or swarmplot

I have a rather simple strip plot with vertical data. planets = sns.load_dataset("planets") sns.stripplot(x="method", y="distance", data=planets, size=4, color=".7") plt.xticks(rotation=45, ha="right") plt.show() I want to plot the mean of each…
BBQuercus
  • 819
  • 1
  • 11
  • 28
7
votes
1 answer

Avoiding repeated legend in seaborn boxplot overlaid by swarmplot

In the seaborn based plot below, I am making a box plot overlaid by a swarm plot. Both are subset by hue. Is there any way I can not have them repeated twice in the legend though? Here is my code: ax = sns.boxplot(x=name_xaxis, y=name_col, hue=hue,…
user308827
  • 21,227
  • 87
  • 254
  • 417
5
votes
1 answer

seaborn pointplot above swarmplot

I try to plot group wise median values using seaborn's pointlot on top of a swarmplot. Even though I call pointPlot second, the point plot ends up behind the swarmplot. How can I change the 'layer order' such that the point plot is in front of the…
jlarsch
  • 2,217
  • 4
  • 22
  • 44
5
votes
1 answer

Obtaining span of plotted points from seaborn swarmplot

I have the following data: import pandas as pd import numpy as np # Generate dummy data. a = np.random.random(75) b = np.random.random(75) - 0.6 c = np.random.random(75) + 0.75 # Collate into a DataFrame df = pd.DataFrame({'a': a, 'b': b, 'c':…
Joses Ho
  • 118
  • 10
4
votes
3 answers

swarmplot with hue affecting marker beyond color

I'm trying to make my swarmplot easier to read in black&white and for people that are color-blind, by having the hue affect not just the color but also another geometrical aspect of the marker. MWE import seaborn as sns import matplotlib.pyplot as…
Miguel
  • 1,293
  • 1
  • 13
  • 30
4
votes
2 answers

Variable sized markers in seaborn swarmplots

For a seaborn swarmplot, I'd like to give different points different marker sizes. In the snippet below, for example, I want to use the marker_size key in plot_data to specify the size of the points in the swarmplot. According to the seaborn…
tkunk
  • 1,378
  • 1
  • 13
  • 19
4
votes
1 answer

How to change the marker size in a swarmplot

I would like to make the data points on my swarmplot larger. The code I have is: sns.swarmplot(x="Heart", y="FirstPersonPronouns", hue="Speech", data=df) sns.set_context("notebook", font_scale=1.8) I have tried scatter_kws but get: Attribute error:…
user5826447
  • 357
  • 1
  • 5
  • 13
3
votes
2 answers

Displaying Averages Graphically on Seaborn Swarm Plots

Let's say I have the following seaborn swarmplot: import seaborn as sns sns.set_theme(style="whitegrid") tips = sns.load_dataset("tips") ax = sns.swarmplot(x="day", y="total_bill", data=tips) What is a simple way to display the average of each of…
Andrea
  • 607
  • 8
  • 21
3
votes
2 answers

Plotting a column-wise bee-swarm plot in Python

I have a sample dataset: A B C 23 45 3 53 78 46 23 68 24 52 68 57 52 79 76 78 79 13 I want to plot a bee-swarm plot in which each column represents on swarm/section. Like: How can I achieve this? I tried…
Aryagm
  • 530
  • 1
  • 7
  • 18
3
votes
3 answers

How to correctly refer to fig and ax with moviepy animation

data_dict = {'x': {(0, 0): 3760.448435678077, (0, 12): 4851.68102541007, (0, 2226): 5297.61518907981, (0, 2479): 4812.134249142693, (0, 2724): 4756.5295525777465, (0, 3724): 3760.448435678077, (0, 4598): 4763.265306122449, (0, 4599):…
jakes
  • 1,964
  • 3
  • 18
  • 50
3
votes
2 answers

How to create a comparative scatter plot/swarm plot in Python/Pylab/Seaborn/Plotly?

For a minimal, reproducible example (reprex) let's assume I have reaction times (seconds) of animals in the following data structure, saved in a .csv file. The file is called…
PolII
  • 107
  • 8
3
votes
1 answer

Variable spacing of discrete categories in seaborn swarmplot

Is there any way to use non-uniform spacing on a discrete axis in seaborn's swarmplots? Here's an example: import pandas as pd import numpy as np import seaborn as sns data = pd.DataFrame({ "x":np.concatenate([np.repeat("A",450),…
Quantum7
  • 3,165
  • 3
  • 34
  • 45
1
2 3 4 5