数据可视化图表-抖动图 (Jittering with stripplot)

通常,多个数据点具有完全相同的 X 和 Y 值。 结果,多个点绘制会重叠并隐藏。 为避免这种情况,请将数据点稍微抖动,以便可以直观地看到它们。 使用 seaborn 的 stripplot() 很方便实现这个功能。

import pandas as pd
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
% matplotlib inline
# import data
df =  pd.read_csv("https://raw.githubusercontent.com/selva86/datasets/master/mpg_ggplot2.csv")
# draw stripplot

fig,ax = plt.subplots(figsize=(16,10),dpi = 80)
sns.stripplot(df.cty,df.hwy,jitter = 0.25,size = 8,ax = ax,linewidth =.5)

# decorations
plt.title('Use jittered plots to avoid overlapping of points', fontsize=22)
plt.show()

猜你喜欢

转载自blog.csdn.net/Cassiel60/article/details/88641371