码迷,mamicode.com
首页 > 其他好文 > 详细

facetgrid学习

时间:2018-10-20 16:32:33      阅读:475      评论:0      收藏:0      [点我收藏+]

标签:his   rom   import   参数   div   先后   ace   tips   ica   

#!/usr/bin/env python
# -*- coding:utf-8 -*-
import numpy as np
import pandas as pd
import seaborn as sns
from scipy import stats
import matplotlib as mpl
import matplotlib.pyplot as plt

sns.set(style="ticks")
np.random.seed(sum(map(ord,"axis_grids")))
tips = sns.load_dataset("tips")
print(tips.head())
#hiat:条形图
g = sns.FacetGrid(tips,col="time")
g.map(plt.hist,"tip");
plt.show()
a = sns.FacetGrid(tips,col="sex",hue="smoker")
a.map(plt.scatter,"total_bill","tip",alpha=.7) #alpha:透明度
a.add_legend();#区分出颜色分别代表什么
plt.show()
#点图,指定颜色等
b = sns.FacetGrid(tips,row="smoker",col="time",margin_titles=True)
b.map(sns.regplot,"size","total_bill",color=".1",
      fit_reg=False,x_jitter=.1)
plt.show()
#盒图,设置大小
c = sns.FacetGrid(tips,col="day",size=4,aspect=.5)
c.map(sns.barplot,"sex","total_bill")
plt.show()
#指定先后顺序,参数都是pandas格式,Categorical分类方法
from pandas import Categorical
ordered_days = tips.day.value_counts().index
print(ordered_days)
ordered_days = Categorical([Thur,Fri, Sat, Sun])
d = sns.FacetGrid(tips,row="day",row_order=ordered_days,
                  size=1.7,aspect=4)
d.map(sns.boxplot,"total_bill")
plt.show()
"""
with sns.axes_style("white"):
    g = sns.FacetGrid(tips, row="sex", col="smoker", margin_titles=True, size=2.5)
g.map(plt.scatter, "total_bill", "tip", color="#334488", edgecolor="white", lw=.5);
g.set_axis_labels("Total bill (US Dollars)", "Tip");
g.set(xticks=[10, 30, 50], yticks=[2, 6, 10]);
g.fig.subplots_adjust(wspace=.02, hspace=.02);
#g.fig.subplots_adjust(left  = 0.125,right = 0.5,bottom = 0.1,top = 0.9, wspace=.02, hspace=.02)

iris = sns.load_dataset("iris")
g = sns.PairGrid(iris)
g.map(plt.scatter);

g = sns.PairGrid(iris, hue="species")
g.map_diag(plt.hist)
g.map_offdiag(plt.scatter)
g.add_legend();

g = sns.PairGrid(iris, vars=["sepal_length", "sepal_width"], hue="species")
g.map(plt.scatter);

g = sns.PairGrid(tips, hue="size", palette="GnBu_d")
g.map(plt.scatter, s=50, edgecolor="white")
g.add_legend();
"""

 

facetgrid学习

标签:his   rom   import   参数   div   先后   ace   tips   ica   

原文地址:https://www.cnblogs.com/lifengwu/p/9821612.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!