%matplotlib inline import numpy as np import pandas as pd from scipy import stats, integrate import matplotlib as mpl from matplotlib import pyplot as plt import seaborn as sns1234567
data = sns.load_dataset("iris") data.head() # 萼片长度,萼片宽度,花瓣长度,花瓣宽度,种类123 sepal_lengthsepal_widthpetal_lengthpetal_widthspecies05.13.51.40.2setosa14.93.01.40.2setosa24.73.21.30.2setosa34.63.11.50.2setosa45.03.61.40.2setosa
data['sepal_size']=data['sepal_length']*data['sepal_width'] data['petal_size']=data['petal_length']*data['petal_width']12 萼片与花瓣
sns.lmplot(x='sepal_size',y='petal_size',data=data)1
<seaborn.axisgrid.FacetGrid at 0x7fea04b37550> 1
g = sns.PairGrid(data, x_vars=["species"], y_vars=["sepal_size", "petal_size"], aspect=2, size=4) g.map(sns.violinplot, palette="pastel");12345
# your code sns.jointplot(x='sepal_length',y='petal_length',data=data,kind='kde')12
/opt/ds/local/lib/python2.7/site-packages/numpy/ma/core.py:6385: MaskedArrayFutureWarning: In the future the default for ma.minimum.reduce will be axis=0, not the current None, to match np.minimum.reduce. Explicitly pass 0 or None to silence this warning. return self.reduce(a) /opt/ds/local/lib/python2.7/site-packages/numpy/ma/core.py:6385: MaskedArrayFutureWarning: In the future the default for ma.maximum.reduce will be axis=0, not the current None, to match np.maximum.reduce. Explicitly pass 0 or None to silence this warning. return self.reduce(a) <seaborn.axisgrid.JointGrid at 0x7fe9fc6fd250> 12345678910
data = sns.load_dataset("tips") data.head() # 总消费,小费,性别,吸烟与否,就餐星期,就餐时间,就餐人数123 total_billtipsexsmokerdaytimesize016.991.01FemaleNoSunDinner2110.341.66MaleNoSunDinner3221.013.50MaleNoSunDinner3323.683.31MaleNoSunDinner2424.593.61FemaleNoSunDinner4 小费与总消费
sns.lmplot(x='total_bill',y='tip',data=data)1
<seaborn.axisgrid.FacetGrid at 0x7fe9ff3afed0> 1
sns.boxplot(y='tip',x='sex',data=data)1
<matplotlib.axes._subplots.AxesSubplot at 0x7fe9ff1651d0> 1
sns.boxplot(y='tip',x='smoker',data=data)1
<matplotlib.axes._subplots.AxesSubplot at 0x7fe9fd4dac10> 1
day=data['day'].unique() day12
[Sun, Sat, Thur, Fri] Categories (4, object): [Sun, Sat, Thur, Fri]
data_week=pd.DataFrame(('weekend' if x in ['Sun','Sat'] else 'weekday' for x in data.day),index=data.index,columns=['week']) data_expand=pd.merge(data,data_week,left_index=True,right_index=True) data_expand.head()123 total_billtipsexsmokerdaytimesizeweek016.991.01FemaleNoSunDinner2weekend110.341.66MaleNoSunDinner3weekend221.013.50MaleNoSunDinner3weekend323.683.31MaleNoSunDinner2weekend424.593.61FemaleNoSunDinner4weekend
sns.boxplot(y='tip',x='week',data=data_expand)1
<matplotlib.axes._subplots.AxesSubplot at 0x7fe9ff533c10> 1
sns.violinplot(x='time',y='tip',data=data)1
<matplotlib.axes._subplots.AxesSubplot at 0x7fe9ffcd35d0> 1
sns.violinplot(x='size',y='tip',data=data)1
<matplotlib.axes._subplots.AxesSubplot at 0x7fe9ffef5650> 1
# your code sns.barplot(x='sex',y='tip',hue='smoker',data=data)12
<matplotlib.axes._subplots.AxesSubplot at 0x7fe9ff4e3d10> 1
data = sns.load_dataset("titanic") data.head() # 幸存与否,仓位等级,性别,年龄,堂兄弟姐妹数,父母子女数,票价,上船港口缩写,仓位等级,人员分类,是否成年男性,所在甲板,上船港口,是否幸存,是否单独乘船123 survivedpclasssexagesibspparchfareembarkedclasswhoadult_maledeckembark_townalivealone003male22.0107.2500SThirdmanTrueNaNSouthamptonnoFalse111female38.01071.2833CFirstwomanFalseCCherbourgyesFalse213female26.0007.9250SThirdwomanFalseNaNSouthamptonyesTrue311female35.01053.1000SFirstwomanFalseCSouthamptonyesFalse403male35.0008.0500SThirdmanTrueNaNSouthamptonnoTrue 幸存or遇难:不同仓位影响?
sns.violinplot(x='class',y='survived',data=data)1
<matplotlib.axes._subplots.AxesSubplot at 0x7fe9fcdcea50> 1
sns.violinplot(x='alive',y='fare',data=data)1
<matplotlib.axes._subplots.AxesSubplot at 0x7fe9fcd213d0> 1
sns.violinplot(x='alive',y='age',data=data)1
<matplotlib.axes._subplots.AxesSubplot at 0x7fe9fcbd83d0> 1
sns.violinplot(x='embark_town',y='pclass',data=data)1
<matplotlib.axes._subplots.AxesSubplot at 0x7fe9fcaa7690> 1
sns.violinplot(x='alive',y='sibsp',data=data)1
<matplotlib.axes._subplots.AxesSubplot at 0x7fe9fc9f41d0> 1
sns.violinplot(x='alive',y='parch',data=data)1
<matplotlib.axes._subplots.AxesSubplot at 0x7fe9fc944d10> 1
# your code sns.barplot(x='alone',y='survived',data=data)12
<matplotlib.axes._subplots.AxesSubplot at 0x7fe9fc632ad0> 1
sns.lmplot(x='age',y='fare',data=data)1
<seaborn.axisgrid.FacetGrid at 0x7fe9fc5ba110> 1
sns.barplot(x='sex',y='pclass',data=data)1
<matplotlib.axes._subplots.AxesSubplot at 0x7fe9fc508c10> 1
sns.lmplot(x='pclass',y='age',data=data,x_jitter=0.2)1
<seaborn.axisgrid.FacetGrid at 0x7fe9fc499150> 1
相关知识
如何用python代码做可视化 – PingCode
python 可视化包 Bokeh
基于Python实现交互式数据可视化的工具(用于Web)
如何利用Python的Seaborn和Matplotlib库对鸢尾花数据集进行数据可视化分析,并通过可视化结果分析不同鸢尾花种类的特征分布差异?
利用Python进行数据可视化常见的9种方法!超实用!
使用python对鸢尾花数据进行预处理和可视化
Python数据可视化中常用的绘图库有哪些? Python常用的绘图库
echart 三维可视化地图
在Python中用Seaborn美化图表的3个示例
Python编程之美:探索海棠花算法在数据可视化中的应用与实践
网址: Python可视化seaborn练习题 https://m.huajiangbk.com/newsview1946808.html
上一篇: 花瓣地图最新版本app下载 |
下一篇: Python数据可视化 pyec |