【数据分析可视化】seaborn强大的调色功能

2020-07-07 18:12:09 浏览数 (1)

代码语言:javascript复制
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
代码语言:javascript复制
def sinplot():
    x = np.linspace(0, 14, 100)
    # 设置画布大点
    plt.figure(figsize=(8,6))
    for i in range(4):
        plt.plot(x, np.sin(x i) * (i 0.75), label='sin(x %s)*(%s 0.75)'% (i,i))
    plt.legend()
代码语言:javascript复制
sinplot()
代码语言:javascript复制
import seaborn as sns
代码语言:javascript复制
sinplot()
代码语言:javascript复制
# 调色板 RGB
sns.color_palette() 
代码语言:javascript复制
[(0.12156862745098039, 0.4666666666666667, 0.7058823529411765),
 (1.0, 0.4980392156862745, 0.054901960784313725),
 (0.17254901960784313, 0.6274509803921569, 0.17254901960784313),
 (0.8392156862745098, 0.15294117647058825, 0.1568627450980392),
 (0.5803921568627451, 0.403921568627451, 0.7411764705882353),
 (0.5490196078431373, 0.33725490196078434, 0.29411764705882354),
 (0.8901960784313725, 0.4666666666666667, 0.7607843137254902),
 (0.4980392156862745, 0.4980392156862745, 0.4980392156862745),
 (0.7372549019607844, 0.7411764705882353, 0.13333333333333333),
 (0.09019607843137255, 0.7450980392156863, 0.8117647058823529)]
代码语言:javascript复制
sns.palplot(sns.color_palette())
代码语言:javascript复制
pal_style = ['deep','muted','pastel','bright', 'dark', 'colorblind']
代码语言:javascript复制
# 定义色板
sns.palplot(sns.color_palette('dark'))
代码语言:javascript复制
sns.set_palette(sns.color_palette('dark'))
sinplot()
代码语言:javascript复制
# 恢复默认状态
sns.set()
代码语言:javascript复制
sinplot()
代码语言:javascript复制
# 当前范围内 指定色板
with sns.color_palette('dark'):
    sinplot()
代码语言:javascript复制
sinplot()
代码语言:javascript复制
# 突破色板是6的限制
pal_1 = sns.color_palette([(0.5,0.1,0.7),(0.3,0.1,0.9)])
pal_1
代码语言:javascript复制
[(0.5, 0.1, 0.7), (0.3, 0.1, 0.9)]
代码语言:javascript复制
sns.palplot(pal_1)
代码语言:javascript复制
# 快捷定义颜色
sns.color_palette('hls', 8)
代码语言:javascript复制
[(0.86, 0.3712, 0.33999999999999997),
 (0.86, 0.7612000000000001, 0.33999999999999997),
 (0.5688000000000001, 0.86, 0.33999999999999997),
 (0.33999999999999997, 0.86, 0.5012000000000001),
 (0.33999999999999997, 0.8287999999999999, 0.86),
 (0.33999999999999997, 0.43879999999999986, 0.86),
 (0.6311999999999998, 0.33999999999999997, 0.86),
 (0.86, 0.33999999999999997, 0.6987999999999996)]
代码语言:javascript复制
sns.palplot(sns.color_palette('hls', 8))
代码语言:javascript复制

官网

0 人点赞