bins = np.array([0, 0.5, 1, 2, 10]) # 股价上涨的公司 shares_up = shares_price[shares_price['increase'] > 0] # 按涨幅进行分组 shares_up['label'] = pd.cut(shares_up['increase'], bins) # 分组统计 up_label_count = shares_up[['label', 'code']].groupby('label').count() up_label_count['占比'] = up_label_count['code'] / up_label_count.sum().values sns.barplot(x=up_label_count['占比'], y=up_label_count.index)修改代码,使配色好看
时间: 2024-01-20 07:04:00 浏览: 71
rxtx-2.2pre2-bins.zip
bins = np.array([0, 0.5, 1, 2, 10])
shares_up = shares_price[shares_price['increase'] > 0]
shares_up['label'] = pd.cut(shares_up['increase'], bins)
up_label_count = shares_up[['label', 'code']].groupby('label').count()
up_label_count['占比'] = up_label_count['code'] / up_label_count.sum().values
plt.figure(figsize=(8, 6))
sns.set(style="whitegrid")
sns.barplot(x=up_label_count['占比'], y=up_label_count.index, palette="Blues_d")
plt.xlabel("占比", size=12)
plt.ylabel("涨幅", size=12)
plt.title("股价上涨的公司涨幅分布", size=14)
阅读全文