Morning. I am trying to create two subplots (1 row and 2 columns). 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. Once I try using fig.add_subplot() or plt.subplot(), I get an error with the 'Date' column of the 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'
I suggest using the object oriented API of 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")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.