stripplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, jitter=True, dodge=False, orient=None, color=None, palette=None, size=5, edgecolor='gray', linewidth=0, ax=None, **kwargs)
import seaborn as sns
from matplotlib import pyplot as plt
sns.set_style('darkgrid')
tips = sns.load_dataset('tips')
sns.stripplot(x='day', y='total_bill', data=tips)
plt.show()
其中jitter参数可以控制抖动程度,可以是bool型也可以是具体数值,抖动可以减少数据重叠
不使用抖动(jitter=False) 使用抖动(jitter=True)
当设置hue参数时,根据hue参数进行不同颜色显示,例如,设置hue='smoker'
当有hue参数时,设置dodge参数可以分离不用类别数据,例如,设置dodge=True
swarmplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, dodge=False, orient=None, color=None, palette=None, size=5, edgecolor='gray', linewidth=0, ax=None, **kwargs)
import seaborn as sns
from matplotlib import pyplot as plt
sns.set_style('darkgrid')
tips = sns.load_dataset('tips')
sns.swarmplot(x='day', y='total_bill', data=tips, hue='sex')
plt.show()
当x为数值型变量
import seaborn as sns
from matplotlib import pyplot as plt
sns.set_style('darkgrid')
tips = sns.load_dataset('tips')
ax=sns.swarmplot(x='size', y='total_bill',data=tips.query("size != 7"))
plt.show()
其中tips.query("size != 7")表示绘制x中size != 7的数据
通过order设置x数据显示顺序,例如,设置order=[1, 3, 2, 4, 5, 6]
import seaborn as sns
from matplotlib import pyplot as plt
sns.set_style('darkgrid')
tips = sns.load_dataset('tips')
ax=sns.swarmplot(x='size', y='total_bill', order=[1, 3, 2, 4, 5, 6],data=tips.query("size != 7"))
plt.show()
可以看到size=2和size=3的顺序交换了
交换x,y轴数据对于当类别名称相对较长或有许多类别时有帮助
import seaborn as sns
from matplotlib import pyplot as plt
sns.set_style('darkgrid')
tips = sns.load_dataset('tips')
ax = sns.swarmplot(y='day', x='total_bill', data=tips)
plt.show()
也可以旋转一下坐标
import seaborn as sns
from matplotlib import pyplot as plt
sns.set_style('darkgrid')
tips = sns.load_dataset('tips')
ax = sns.swarmplot(x='size', y='total_bill', data=tips)
ax.set_xticklabels(ax.get_xticklabels(), rotation=-45)
plt.show()
boxplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, orient=None, color=None, palette=None, saturation=0.75, width=0.8, dodge=True, fliersize=5, linewidth=None, whis=1.5, notch=False, ax=None, **kwargs)
import seaborn as sns
from matplotlib import pyplot as plt
sns.set_style('darkgrid')
tips = sns.load_dataset('tips')
ax = sns.boxplot(x="day", y="total_bill", hue='smoker', dodge=True, data=tips)
ax.legend(shadow=False, fancybox=False, ncol=1, fontsize=10, loc='upper left')
plt.show()
其中hue参数,dodge参数的设置前面已经提到过,这里不再赘述
import seaborn as sns
from matplotlib import pyplot as plt
sns.set_style('darkgrid')
tips = sns.load_dataset('tips')
ax = sns.boxplot(x="day", y="total_bill", hue='smoker', dodge=True, data=tips)
ax.legend(shadow=False, fancybox=False, ncol=1, fontsize=10, loc='upper left')
plt.show()
boxenplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, orient=None, color=None, palette=None, saturation=0.75, width=0.8, dodge=True, k_depth='proportion', linewidth=None, scale='exponential', outlier_prop=None, ax=None, **kwargs)
import seaborn as sns
from matplotlib import pyplot as plt
sns.set_style('darkgrid')
diamonds = sns.load_dataset("diamonds")
ax = sns.boxenplot(x="color", y="price", data=diamonds.sort_values("color"))
#ax.legend(shadow=True, fancybox=True, ncol=1, fontsize=10, loc='upper left')
plt.show()
violinplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, bw='scott', cut=2, scale='area', scale_hue=True, gridsize=100, width=0.8, inner='box', split=False, dodge=True, orient=None, linewidth=None, color=None, palette=None, saturation=0.75, ax=None, **kwargs)
import seaborn as sns from matplotlib import pyplot as plt sns.set_style('darkgrid') tips = sns.load_dataset("tips") ax = sns.violinplot(y="total_bill", x="day", inner="stick", hue="sex", split=True, data=tips) #ax.legend(shadow=True, fancybox=True, ncol=1, fontsize=10, loc='upper right') plt.show()
inner参数可以设置为 {"box", "quartile", "point", "stick", None}
如果是box,绘制一个小型的箱线图,如果是quartiles,绘制四分位数分布,如果是point或者stick,画每一个数据,如果是None,不做任何修饰
barplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, estimator=
import seaborn as sns from matplotlib import pyplot as plt sns.set_style('darkgrid') titanic = sns.load_dataset("titanic") ax = sns.barplot(x="sex", y="survived", hue="class", data=titanic) #ax.legend() plt.show()
其中ci参数可以设置是否绘制error bar,如果为整数,则绘制估计数周围整数大小的置信区间,如果为sd,绘制标准差,如果为None,不绘制error bar。另外置信区间范围内数值是使用bootstrapping方法计算出来的
Bootstrapping算法,指的就是利用有限的样本资料经由多次重复抽样,重新建立起足以代表母体样本分布的新样本。bootstrapping方法的实现很简单,假设抽取的样本大小为n:
在原样本中有放回的抽样,抽取n次。每抽一次形成一个新的样本,重复操作,形成很多新样本,通过这些样本就可以计算出样本的一个分布。
countplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, orient=None, color=None, palette=None, saturation=0.75, dodge=True, ax=None, **kwargs)
import seaborn as sns from matplotlib import pyplot as plt sns.set_style('darkgrid') titanic = sns.load_dataset("titanic") ax = sns.countplot(x="deck", palette="ch:.25", data=titanic) #ax.legend() plt.show()
countplot显示的是观察值,而不是统计值
pointplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, estimator=
import seaborn as sns from matplotlib import pyplot as plt sns.set_style('darkgrid') titanic = sns.load_dataset("titanic") ax = sns.pointplot(x="class", y="survived", hue="sex", palette={"male": "g", "female": "m"}, markers=["^", "o"], linestyles=["-", "--"], data=titanic) #ax.legend() plt.show()
通过设置palette,不同marker和不同linestyle来区分不同类别