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

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

import pandas as pd
%matplotlib inline
import seaborn as sns
import matplotlib.pyplot as plt

sns.set(style="white")
sns.color_palette("deep")
sns.set_color_codes("deep")

# Initialize the matplotlib figure
fig, ax = plt.subplots(figsize=(10, 7))
plt.title("feature distribution with labels")

top15 = data[data['invest_times']<=10]
# Plot the total attack by year
p = 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 label
ax.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

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

农民小飞侠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值