Seaborn绘图01

基础篇

准备工作

import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
import numpy as np
import pandas as pd

#plt.rcParams[‘font.sans-serif’] = [‘SimHei’] #用来正常显示中文标签
plt.rcParams[‘axes.unicode_minus’] = False #用来正常显示负号
sns.set_style(‘darkgrid’,{‘font.sans-serif’:[‘SimHei’,‘Arial’]})

import warnings # 去除部分警告信息
warnings.filterwarnings(‘ignore’)

names = sns.get_dataset_names()
print(names)

matplotlib原始的柱状图

for i in names:
sns.load_dataset(i)
plt.bar([1,2,3,4,5],[3,6,9,2,5]) #matplotlib原始的柱状图

sns.set()
plt.bar([1,2,3,4,5],[3,6,9,2,5])

注意背景变换

sns.set_style(“whitegrid”)
plt.bar([1,2,3,4,5],[3,6,9,2,5])

sns.set_style(“white”)
plt.bar([1,2,3,4,5],[3,6,9,2,5])

sns.set_style(“darkgrid”)
plt.bar([1,2,3,4,5],[3,6,9,2,5])
sns.despine(left=True,bottom=True)

去除Seaborn图脊,默认去除上边和右边

命名

sns.set_style(‘darkgrid’,{‘font.sans-serif’:[‘SimHei’,‘Arial’]})
plt.bar([1,2,3,4,5],[3,6,9,2,5])
plt.title(“柱状图”)

sns.set_context(“poster”)
plt.bar([1,2,3,4,5],[3,6,9,2,5])
plt.title(“柱状图”)

调色板

color_palette方法返回默认的调色板信息

current_palette = sns.color_palette()
print(current_palette)

sns.palplot(sns.color_palette(“pastel”))

使用自定义颜色,构造颜色版

color = [‘red’,‘orange’,‘yellow’,‘green’,‘pink’,‘blue’,‘black’,]
print(sns.color_palette(color))
sns.palplot(sns.color_palette(color))

颜色渐变的调色板

sns.palplot(sns.color_palette(“Blues”))

画个浅绿色的柱状图

sns.set_palette(“YlGn”)
sns.barplot([2,3,4,5],[0,8,1,9])

上一篇:Spring Cloud 系列之 Consul 配置中心


下一篇:Qt QLabel设置背景色