python:如何用从pandas dataframe中的列中获取的值构造一个joyplot作为y轴
我有一个DataFrame DF,其中列Drested_day由在2022-05-08到2022-05-12之间的日期组成。我还有另一列名为GAS_PRICE,它由天然气的价格组成。我想构建一个欢笑图,以便在每个日期,它在y轴上显示gas_price,并在x轴中具有munite_elapsed_from_start_of_day。如果这不起作用,我们也可以使用RidgePlot或任何其他图。
这是我编写的代码,但没有达到我的目的。
from joypy import joyplot
import matplotlib.pyplot as plt
df['extracted_day'] = df['extracted_day'].astype(str)
joyplot(df, by = 'extracted_day', column = 'minutes_elapsed_from_start_of_day',figsize=(14,10))
plt.xlabel("Number of minutes elapsed throughout the day")
plt.show()
I have a dataframe df in which the column extracted_day consists of dates ranging between 2022-05-08 to 2022-05-12. I have another column named gas_price, which consists of the price of the gas. I want to construct a joyplot such that for each date, it shows the gas_price in the y axis and has minutes_elapsed_from_start_of_day in the x axis. We may also use ridgeplot or any other plot if this doesn't work.
This is the code that I have written, but it doesn't serve my purpose.
from joypy import joyplot
import matplotlib.pyplot as plt
df['extracted_day'] = df['extracted_day'].astype(str)
joyplot(df, by = 'extracted_day', column = 'minutes_elapsed_from_start_of_day',figsize=(14,10))
plt.xlabel("Number of minutes elapsed throughout the day")
plt.show()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用模拟数据创建数据框:
然后创建JoyPlot。重要的是要设置
kint ='value'
,因为您不希望JoyPlot显示KDES(内核密度估算,JoyPlot的默认值),但是RAWgas_price
value:由此产生的JoyPlot看起来像这样(假汽油价格由线的Y值代表):

Create dataframe with mock data:
Then create the joyplot. It is important that you set
kind='values'
, since you do not want joyplot to show KDEs (kernel density estimates, joyplot's default) but the rawgas_price
values:The resulting joyplot looks like this (the fake gas prices are represented by the y-values of the lines):
