如何使用Seaborn或Matplotlib制作相同的Crosstab线图?
我有三列。但是我有兴趣彼此绘制两列。列的数据类型是DateTime和对象。 DateTime列名是 start_at ,对象列名是 member_casual 。 我想要 start_at (每小时)在我的x轴上, emment_causal (计数)y轴上。我使用此代码
my DaraFrame(df) looks like this
rideable_type started_at member_casual
electric_bike 2021-06-13 14:31:28 casual
classic_bike 2021-06-04 11:18:02 member
classic_bike 2021-06-04 09:49:35 casual
calssic_bike 2021-06-04 09:55:34 casual
electric_bike 2021-06-04 14:05:51 casual
classic_bike 2021-06-04 14:09:59 member
electric_bike 2021-06-03 19:32:01 casual
electric_bike 2021-06-10 16:30:10 member
... ... ...
... ... ...
此代码为我提供了计数成员_casual(y轴)的行图,相对于小时时间(x轴)。
pd.crosstab(df.started_at.dt.hour,df.member_casual).plot(kind='line', ax = ax)
谁能告诉我如何使用Seaborn或Matplotlib绘制相同的情节?
我,M Begineer,这是我能做的最好的。
try_1
plt.plot(df.started_at.dt.hour, df.member_casual)
try_2
sns.lineplot(df.started_at.dt.hour, hue = df.member_casual)
of course of两行代码都给了我一个错误。
I have three columns. But I'm interested in plotting two columns with respect to each other. The datatype of the columns are datetime and object. The datetime column name is started_at and object column name is member_casual.
I want started_at(hourly) on my x-axis and member_causal(count) on y-axis. I use this code
my DaraFrame(df) looks like this
rideable_type started_at member_casual
electric_bike 2021-06-13 14:31:28 casual
classic_bike 2021-06-04 11:18:02 member
classic_bike 2021-06-04 09:49:35 casual
calssic_bike 2021-06-04 09:55:34 casual
electric_bike 2021-06-04 14:05:51 casual
classic_bike 2021-06-04 14:09:59 member
electric_bike 2021-06-03 19:32:01 casual
electric_bike 2021-06-10 16:30:10 member
... ... ...
... ... ...
this code gives me line plot of counting member_casual(y-axis) with respect to hourly time(x-axis).
pd.crosstab(df.started_at.dt.hour,df.member_casual).plot(kind='line', ax = ax)
Can anyone tell me how to draw the same plot using seaborn or matplotlib ?
I,m begineer so this is the best I can do.
try_1
plt.plot(df.started_at.dt.hour, df.member_casual)
try_2
sns.lineplot(df.started_at.dt.hour, hue = df.member_casual)
ofcourse both lines of code gives me an error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您首先需要计算每小时发生的情况,例如与您已经相同的方式:
Matplotlib逐步:
Matplotlib短形式:
Seaborn:Seaborn:
You first need to count the hourly occurrences, for instance the same way as you already did:
matplotlib step by step:
matplotlib short form:
seaborn: