Skip to content

Instantly share code, notes, and snippets.

@muhammadanas0716
Last active January 14, 2023 17:10
Show Gist options
  • Save muhammadanas0716/23c071b32ebf9f0b16bfddc8cbb6ff5c to your computer and use it in GitHub Desktop.
Save muhammadanas0716/23c071b32ebf9f0b16bfddc8cbb6ff5c to your computer and use it in GitHub Desktop.
Another option to avoid the problem of points overlap is the increase the size of the dot depending on how many points lie in that spot. So, larger the size of the point more is the concentration of points around that.
# Imports
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
# Import Data
df = pd.read_csv("https://raw.githubusercontent.com/selva86/datasets/master/mpg_ggplot2.csv")
df_counts = df.groupby(['hwy', 'cty']).size().reset_index(name='counts')
# Draw Stripplot
fig, ax = plt.subplots(figsize=(16,10), dpi= 80)
sns.stripplot(x=df_counts.cty, y=df_counts.hwy, sizes=(df_counts.counts*20), hue=df_counts.counts, ax=ax)
# Decorations
plt.title('Counts Plot - Size of circle is bigger as more points overlap', fontsize=22)
plt.show()
@muhammadanas0716
Copy link
Author

Right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment