import panda as pd
x = pd.DataFrame(b.transpose(),columns['x','y','width','height'])
#b.shape = [num_labels,4]
#使用pd来建立一种数据结构,使用类似excel表来管理b的每一列
import seaborn as sns
sns.pairplot(x, corner=True, diag_kind='auto', kind='hist', diag_kws=dict(bins=50), plot_kws=dict(pmax=0.9))
使用鸢尾花数据集看效果
原图
corner=True
diag_kind = auto
kind='hist'
diag_kws=dict(bins=50)
plot_kws=dict(pmax=0.9)
kws:用于控制对角线上图的样式
plot_kws:用于控制非对角线图的样式
matplotlib.pyplt.hist
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
a = np.array([0]*10)
b = np.array([1]*9)
c = np.array([2]*8)
d = np.array([3]*7)
e = np.concatenate((a,b,c,d),axis=0)
print (e)
#[0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2]
n, bins, patches= plt.hist(e, bins=np.linspace(0, nc, nc + 1) - 0.5, rwidth=0.8) #np.linespace 从0到5 一共6个数字(nc+1)6个柱子 主子间距0.8
#plt.plot(bins)
plt.xlabel('classes')
plt.savefig('1222_hist_plot.jpg', dpi=200)
plt.close()
print (e)
结果
如果把
plt.plot(bins)
取消注释
这是一条数据分析线,但往往是不必要的。
sns与plt.subplot
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
data=sns.load_dataset("iris")
ax = plt.subplots(1, 2, figsize=(8,4), tight_layout=True)[1].ravel()
sns.histplot(data,x='petal_length',y='petal_width',ax=ax[1])
sns.histplot(data,x='sepal_length',y='sepal_width',ax=ax[0])
ax[1].spines['right'].set_visible(True)
ax[0].spines['left'].set_visible(True)
plt.savefig('1222.jpg', dpi=200)
plt.close()
改为,bins能明显的看出在控制粒度
sns.histplot(data,x='petal_length',y='petal_width',ax=ax[1],bins=50)
改为,pmax的解释 A value in [0, 1] that sets that saturation point for the colormap at a value such that cells below is constistute this proportion of the total count (or other statistic, when used).
将pmax作为最大阈值,小于这个阈值按比例画热力图,大于这个阈值直接设为max
sns.histplot(data,x='sepal_length',y='sepal_width',ax=ax[0],pmax=0.1)