发布时间:2023-05-29 12:30
先导入相关模块和数据集。
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
tips = sns.load_dataset('tips')
tips.head()
琴形图结合了箱线图和和密度估计图的特点。可以通过videoplot() 函数来绘制琴形图。
sns.set(style='whitegrid', color_codes=True)
sns.violinplot(x='day', y='total_bill', data=tips)
sns.set(style='whitegrid', color_codes=True)
sns.violinplot(x='day', y='total_bill', hue='time', data=tips)
上面的图,其实并不是很直观,而且不好看。所以利用split 参数对分类数据进行切分,这样琴形图不同的颜色代表不同的类别。还可以利用inner参数对每个数据可视化,而不是只能看箱线图的哪几个统计值。
sns.set(style='whitegrid', color_codes=True)
fig, axes = plt.subplots(1,2,figsize=(10,5))
sns.violinplot(x='day', y='total_bill', hue='sex', data=tips, split=True, ax=axes[0])
sns.violinplot(x='day', y='total_bill', hue='time', data=tips, split=True, inner='stick', palette='Set3', ax=axes[1])
其实,分类函数是可以一起使用,这样就实现了更加强大的可视化效果。
sns.set(style='whitegrid', color_codes=True)
fig, axes = plt.subplots(1,2,figsize=(10,5))
sns.violinplot(x='day', y='total_bill',data=tips,inner=None,ax=axes[0])
sns.swarmplot(x='day', y='total_bill',data=tips,color='w', alpha=0.5, ax=axes[0])
sns.boxplot(x='day', y='total_bill',data=tips,ax=axes[1])
sns.stripplot(x='day', y='total_bill',data=tips,jitter=True, color='w', alpha=0.5, ax=axes[1])
Java微服务开发指南-使用Docker和Kubernetes构建可伸缩的微服务
Zilliz x 2022 开源之夏!来 Milvus 和 Towhee 社区,搞开源,拿奖金!
master节点重置后添加node报错_Prometheus监控Kubernetes 集群节点及应用
干货!Labeling Trick: 一个图神经网络多节点表示学习理论
关于GAN训练过程中的报错:one of the variables needed for gradient computation has been modified by an inplace
Python使用wxpy模块实现微信两两群组消息同步功能(推荐)