笔记本Python中直方图子图的错误
我在做什么错?我刚刚开始学习Python而不是R。 我试图在彼此相邻完成三个直方图。他们每个人都是由另一个机场从专栏起点分组的。
这就是我想要看起来的方式
import pandas as pd
import seaborn
import matplotlib.pyplot as plt
flights2_EWR=flights2.loc[flights2['origin'] == 'EWR']
histEWR=seaborn.histplot(x="delay", bins=12, palette="pastel",
data=flights2_EWR)
flights2_EWR=flights2.loc[flights2['origin'] == 'EWR']
histEWR=plt.hist(x="delay", bins=12,
data=flights2_EWR)
flights2_JFK=flights2.loc[flights2['origin'] == 'JFK']
histJFK=plt.hist(x="delay", bins=12,
data=flights2_JFK)
flights2_LGA=flights2.loc[flights2['origin'] == 'LGA']
histLGA=plt.hist(x="delay", bins=12,
data=flights2_LGA)
plt.subplot(1, 3, 1)
plt.hist(histEWR)
plt.subplot(1, 3, 2)
plt.hist(histJFK)
plt.subplot(1, 3, 3)
plt.hist(histLGA)
plt.show()
< ='在'矩形'和'矩形''之间不支持'
What am I doing wrong? I've just started learning Python instead of R.
I'm trying to accomplish three histograms next to each other. Each of them is grouped by another airport from column origin.
This is how I want it too look
I can do sth like this, but it's not enough for me
packages:
import pandas as pd
import seaborn
import matplotlib.pyplot as plt
First I tried with seaborn:
flights2_EWR=flights2.loc[flights2['origin'] == 'EWR']
histEWR=seaborn.histplot(x="delay", bins=12, palette="pastel",
data=flights2_EWR)
There is code with matplotlib
flights2_EWR=flights2.loc[flights2['origin'] == 'EWR']
histEWR=plt.hist(x="delay", bins=12,
data=flights2_EWR)
flights2_JFK=flights2.loc[flights2['origin'] == 'JFK']
histJFK=plt.hist(x="delay", bins=12,
data=flights2_JFK)
flights2_LGA=flights2.loc[flights2['origin'] == 'LGA']
histLGA=plt.hist(x="delay", bins=12,
data=flights2_LGA)
plt.subplot(1, 3, 1)
plt.hist(histEWR)
plt.subplot(1, 3, 2)
plt.hist(histJFK)
plt.subplot(1, 3, 3)
plt.hist(histLGA)
plt.show()
TypeError: '<=' not supported between instances of 'Rectangle' and 'Rectangle'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗨,欢迎来到堆栈溢出。您可以使用 seaborn Distplot 和
col = Origin
(JFK,EWR,LGA)实现这一目标。它将以您的寻找方式创建多个子图。由于我没有您所指的数据,因此使用Seaborn默认情况下使用了企鹅数据集。代码
输出图

Hi and welcome to Stack Overflow. You can achieve this using seaborn distplot and the
col = origin
(JFK, EWR, LGA). It will create multiple subplots the way you are looking for. As I don't have the data you are referring to, used penguins dataset available by default in seaborn.Code
Output Graph
