简体   繁体   English

具有时间序列数据的子图

[英]Subplot with Time Series Data

Morning.早晨。 I am trying to create two subplots (1 row and 2 columns).我正在尝试创建两个子图(1 行和 2 列)。 But am running into some issues.但是我遇到了一些问题。

import matplotlib.pyplot as plt
import seaborn as sns

fig = plt.figure(figsize=(25,10))
ax1 = fig.add
data.Loc2.resample('W').mean().rolling(window=3).mean().plot()
plt.title("Mean weekly windspeed at Loc2")


data.Loc2.resample('M').mean().rolling(window=4).mean().plot()
plt.title("Mean monthly windspeed at Loc2")

Above is what I have but it is creating a single plot with two lines with 'Date' along the x-axis.以上是我所拥有的,但它正在创建一个 plot,其中两条线沿 x 轴带有“日期”。 Once I try using fig.add_subplot() or plt.subplot(), I get an error with the 'Date' column of the dataframe.尝试使用 fig.add_subplot() 或 plt.subplot() 后,dataframe 的“日期”列出现错误。

import matplotlib.pyplot as plt
import seaborn as sns

fig = plt.figure(figsize=(25,10))
axOne = plt.subplot(1,2,1)
y = data.Loc2.resample('W').mean().rolling(window=3).mean()
x = data.Date
data.plot(ax = axOne, x = x, y = y, fontsize = 20, c = "blue")
plt.title("Mean weekly windspeed at Loc2")


data.Loc2.resample('M').mean().rolling(window=4).mean().plot()
plt.title("Mean monthly windspeed at Loc2")

Here is the error that I get whenever I try any of the methods to create subplots.这是我尝试任何方法创建子图时遇到的错误。

AttributeError: 'DataFrame' object has no attribute 'Date' AttributeError: 'DataFrame' object 没有属性 'Date'

I suggest using the object oriented API of matplotlib.我建议使用面向 object 的 API 的 matplotlib。 This is what I would do:这就是我要做的:

fig, axes = plt.subplots(ncols=2, figsize=(25,10))
data.Loc2.resample('W').mean().rolling(window=3).mean().plot(ax=axes[0])
axes[0].set_title("Mean weekly windspeed at Loc2")

data.Loc2.resample('M').mean().rolling(window=4).mean().plot(ax=axes[1])
axes[1].set_title("Mean monthly windspeed at Loc2")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM