[英]Add In Plot Labels to Seaborn Lineplot
I have a dataframe that shows monthly revenue. 我有一个显示月收入的数据框。 There is an additional column that shows the number of locations opened in that month.
另有一列显示该月打开的位置数。
> Date Order Amount Locations Opened
16 2016-05-31 126443.17 2.0
> 17 2016-06-30 178144.27 0.0
18 2016-07-31 230331.96 1.0
> 19 2016-08-31 231960.04 0.0
20 2016-09-30 208445.26 0.0
I'm using seaborn to plot the revenue by month 我正在用seaborn按月绘制收入
sns.lineplot(x="Date", y="Order Amount",
data=total_monthly_rev).set_title("Total Monthly Revenue")
I've been trying, unsuccessfully, to use the third column, Locations Opened, to add supporting text to the lineplot so I can show the number of locations opened in a month, where Locations Opened > 0. 我一直在尝试使用第三列“已打开的位置”来向线图添加支持文本,但未成功,因此我可以显示一个月内打开的位置数,其中“已打开的位置”> 0。
IIUC, use text
: IIUC,使用
text
:
plt.figure(figsize=(12, 5))
sns.lineplot(x="Date", y="Order Amount", data=total_monthly_rev).set_title("Total Monthly Revenue")
# Using a variable to manage how above/below text should appear
slider = 1000
for i in range(total_monthly_rev.shape[0]):
if total_monthly_rev['LocationsOpened'].iloc[i] > 0:
plt.text(total_monthly_rev.Date.iloc[i],
total_monthly_rev['Order Amount'].iloc[i] + slider,
total_monthly_rev['LocationsOpened'].iloc[i])
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.