做数据集统计脚本

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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值