import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# 一些默认配置,使得图表更美观
large = 22; med = 16; small = 12
params = {'axes.titlesize': large,
'legend.fontsize': med,
'figure.figsize': (16, 10),
'axes.labelsize': med,
'axes.titlesize': med,
'xtick.labelsize': med,
'ytick.labelsize': med,
'figure.titlesize': large}
plt.rcParams.update(params)
plt.style.use('seaborn-whitegrid')
sns.set_style("white")
# 设置matplotlib正常显示中文
plt.rcParams['font.sans-serif']=['SimHei'] # 用黑体显示中文
plt.rcParams['axes.unicode_minus']=False
def plot_1kde(title, x, cumulative=False):
plt.figure(figsize=(12,10), dpi= 80)
sns.kdeplot(x, cumulative=cumulative, shade=True, color='r') # cumulative为密度累计, shade表示线下颜色为阴影, color表示颜色是红色
plt.title(title, fontsize=22)
plt.show()
def plot_2kde(title, x, y):
plt.figure(figsize=(12,10), dpi= 80)
sns.kdeplot(x, y, shade=True, cbar=True) # cbar表示颜色棒
plt.title(title, fontsize=22)
plt.show()
# 生成一些随机数
rs = np.random.RandomState(80)
s = pd.Series(rs.randn(70) * 100)
h = pd.Series(rs.randn(70) * 100)
plot_1kde('测试图', s)
plot_2kde('测试图2', s, h)
# 生成一些随机数
rs = np.random.RandomState(80)
s = pd.Series(rs.randn(70) * 100)