前言:
现在姐妹们对“apacheaxis2kernel”都比较关切,看官们都想要知道一些“apacheaxis2kernel”的相关知识。那么小编在网络上网罗了一些有关“apacheaxis2kernel””的相关文章,希望我们能喜欢,姐妹们快快来了解一下吧!简介
Seaborn是一个统计图形绘制库
它默认具有非常漂亮的样式
它对pandas dataframe对象支持的非常好
安装
conda install seaborn
或
pip install seaborn
在线文档:
seaborn可以绘制出多种图形例如:
Distribution Plots
本文介绍如何使用Seaborn绘制数据分布图,可以使用的函数包括:
distplotjointplotpairplotrugplotkdeplot
首先打开Jupyter Notebook
导入数据
import seaborn as sns
%matplotlib inline
数据
Seaborn本身包含一些数据集,例如tips
tips = sns.load_dataset('tips')
tips.head()
distplot
distplot显示单变量观测值的分布
sns.distplot(tips['total_bill'])
去掉kde只显示直方图
jointplot
可以在二维数据上将两个distplot组合显示,可选项包括:
“scatter”“reg”“resid”“kde”“hex”
sns.jointplot(x='total_bill',y='tip',data=tips,kind='scatter')
sns.jointplot(x='total_bill',y='tip',data=tips,kind='hex')
sns.jointplot(x='total_bill',y='tip',data=tips,kind='reg')
pairplot
pairplot在整个数据集中绘制成对关系(对于数值列),并支持颜色色调参数(用于分类列)。
sns.pairplot(tips)
sns.pairplot(tips,hue='sex',palette='coolwarm')
rugplot
rugplot实际上是一个非常简单的概念,它只是为单变量分布上的每个点画一个破折号,是建立在kde基础上的。
sns.rugplot(tips['total_bill'])
kdeplot
kdeplot是Kernel Density Estimation plots的缩写,这些KDE图替换以高斯分布为中心的每一个观察值。例如
# Don't worry about understanding this code!
# It's just for the diagram below
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
#Create dataset
dataset = np.random.randn(25)
# Create another rugplot
sns.rugplot(dataset);
# Set up the x-axis for the plot
x_min = dataset.min() - 2
x_max = dataset.max() + 2
# 100 equally spaced points from x_min to x_max
x_axis = np.linspace(x_min,x_max,100)
# Set up the bandwidth, for info on this:
url = ''
bandwidth = ((4*dataset.std()**5)/(3*len(dataset)))**.2
# Create an empty kernel list
kernel_list = []
# Plot each basis function
for data_point in dataset:
# Create a kernel for each point and append to list
kernel = stats.norm(data_point,bandwidth).pdf(x_axis)
kernel_list.append(kernel)
#Scale for plotting
kernel = kernel / kernel.max()
kernel = kernel * .4
plt.plot(x_axis,kernel,color = 'grey',alpha=0.5)
plt.ylim(0,1)
# To get the kde plot we can sum these basis functions.
# Plot the sum of the basis function
sum_of_kde = np.sum(kernel_list,axis=0)
# Plot figure
fig = plt.plot(x_axis,sum_of_kde,color='indianred')
# Add the initial rugplot
sns.rugplot(dataset,c = 'indianred')
# Get rid of y-tick marks
plt.yticks([])
# Set title
plt.suptitle("Sum of the Basis Functions")
sns.kdeplot(tips['total_bill'])
sns.rugplot(tips['total_bill'])
sns.kdeplot(tips['tip'])
sns.rugplot(tips['tip'])
后续文章内容:
Distribution PlotsCategorical Data PlotsMatrix PlotsGridsRegression PlotsStyle and ColorSeaborn练习题及答案
标签: #apacheaxis2kernel