Strip plot and swarm plot

A strip is basically a scatter plot where the x-axis represents a categorical variable. Typical uses of a strip plot involve applying a small random jitter value to each data point such that the separation between points becomes clearer:

# Strip plot with jitter value
ax = sns.stripplot(x="population type", y="dollar_price", data=merged_df2, jitter=True)
ax.set_xlabel("Population type")
ax.set_ylabel("BigMac index (US$)")

plt.show()

A swarm plot is very similar to a strip plot, yet the locations of points are adjusted automatically to avoid overlap even if the jitter value is not applied. These plots resemble bees swarming a position, and are likewise named.

If we change the Seaborn function call from sns.stripplot to sns.swarmplot in the preceding code excerpt, the result will be changed to this:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset