python 画带有标签分布的直方图

网友投稿 818 2022-10-01

python 画带有标签分布的直方图

最近在写代码的时候需要可视化一些特征,想了解一下某些离散特征的label分布,其横轴是特征,纵轴是频率,直方图用不同的颜色标记不同的label。我这里分享一下我的代码:

import pandas as pd%matplotlib inlineimport seaborn as snsimport matplotlib.pyplot as pltsns.set(style="white")sns.color_palette("deep")sns.set_color_codes("deep")# Initialize the matplotlib figurefig, ax = plt.subplots(figsize=(10, 7))plt.title("feature distribution with labels")top15 = data[data['invest_times']<=10]# Plot the total attack by yearp = sns.countplot(x="invest_times", data=top15, label="Total label", color="r")g = sns.countplot(x="invest_times", data=top15[top15["label"] == 1], label="label with success", color="b")# Add a legend and informative axis labelax.legend(ncol=2, loc="upper right", frameon=False)p.set_xticklabels(p.get_xticklabels(), rotation=90)sns.despine(left=True, bottom=True)ax.set(ylabel="", xlabel="invest_times")

数据我就不公开了,我是用pandas读取的表格数据,直接调用代码可视化的。

参考文献

[1]. ​​https://github.com/ibmw/Shark-Attack/blob/master/Shark%20Attack.ipynb​​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:微信小程序怎么使用车牌号输入法(微信小程序怎么使用车牌号输入法了)
下一篇:[leetcode] 72. Edit Distance动态规划
相关文章

 发表评论

暂时没有评论,来抢沙发吧~