Travel Tips
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
统计图 barplot() / countplot() / pointplot()
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns %matplotlib inline sns.set_style("whitegrid") sns.set_context("paper") # 设置风格、尺度 import warnings warnings.filterwarnings('ignore') # 不发出警告
barplot() / countplot() / pointplot() iris=sns.load_dataset("titanic",engine='python') iris
# 柱状图 - 置信区间估计
# 置信区间:样本均值 + 抽样误差
titanic = sns.load_dataset("titanic") print(titanic.head()) print('-----') # 加载数据 print(titanic.groupby(['sex','class']).mean()['survived']) print(titanic.groupby(['sex','class']).std()['survived'])
sns.barplot(x="sex", y="survived", hue="class", data=titanic, palette = 'hls', order = ['male','female'], # 筛选类别 capsize = 0.05, # 误差线横向延伸宽度 saturation=.8, # 颜色饱和度 errcolor = 'gray',errwidth = 2, # 误差线颜色,宽度 ci = 'sd' # 置信区间误差 → 0-100内值、'sd'、None )
# 柱状图 - 置信区间估计
sns.barplot(x="day", y="total_bill", hue="sex", data=tips, palette = 'Blues',edgecolor = 'w') tips.groupby(['day','sex']).mean() # 计算数据
# 柱状图 - 置信区间估计
crashes = sns.load_dataset("car_crashes").sort_values("total", ascending=False) print(crashes.head()) # 加载数据
f, ax = plt.subplots(figsize=(6, 15)) # 创建图表 sns.set_color_codes("pastel") sns.barplot(x="total", y="abbrev", data=crashes, label="Total", color="b",edgecolor = 'w') # 设置第一个柱状图 sns.set_color_codes("muted") sns.barplot(x="alcohol", y="abbrev", data=crashes, label="Alcohol-involved", color="b",edgecolor = 'w') # 设置第二个柱状图 ax.legend(ncol=2, loc="lower right") sns.despine(left=True, bottom=True)
# 计数柱状图
# 计数 不用设置y值
sns.countplot(x="class", hue="who", data=titanic,palette = 'magma') #sns.countplot(y="class", hue="who", data=titanic,palette = 'magma') # x/y → 以x或者y轴绘图(横向,竖向) # 用法和barplot相似
# 折线图 - 置信区间估计
sns.pointplot(x="time", y="total_bill", hue = 'smoker',data=tips, palette = 'hls', dodge = True, # 设置点是否分开 join = True, # 是否连线 markers=["o", "x"], linestyles=["-", "--"], # 设置点样式、线型 ) tips.groupby(['time','smoker']).mean()['total_bill'] # 计算数据 # # 用法和barplot相似
Sed ac lorem felis. Ut in odio lorem. Quisque magna dui, maximus ut commodo sed, vestibulum ac nibh. Aenean a tortor in sem tempus auctor
December 4, 2020 at 3:12 pm
Sed ac lorem felis. Ut in odio lorem. Quisque magna dui, maximus ut commodo sed, vestibulum ac nibh. Aenean a tortor in sem tempus auctor
December 4, 2020 at 3:12 pm
Donec in ullamcorper quam. Aenean vel nibh eu magna gravida fermentum. Praesent eget nisi pulvinar, sollicitudin eros vitae, tristique odio.
December 4, 2020 at 3:12 pm
我是 s enim interduante quis metus. Duis porta ornare nulla ut bibendum
Rosie
6 minutes ago