季节性分解图的默认颜色为浅蓝色。 1.如何更改颜色以使每条线条颜色不同? 2.如果每个图不能有单独的颜色,我如何将所有颜色改为红色?
我已经尝试将参数添加到decomposition.plot(color ='red')并在文档中搜索线索。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# I want 7 days of 24 hours with 60 minutes each
periods = 7 * 24 * 60
tidx = pd.date_range('2016-07-01', periods=periods, freq='D')
np.random.seed([3,1415])
# This will pick a number of normally distributed random numbers
# where the number is specified by periods
data = np.random.randn(periods)
ts = pd.Series(data=data, index=tidx, name='TimeSeries')
decomposition = sm.tsa.seasonal_decompose(ts, model ='additive')
fig = decomposition.plot()
plt.show()
您发布的代码中的decomposition
对象在绘图方法中使用pandas。我没有看到将颜色直接传递给plot
方法的方法,并且它不需要** kwargs。
解决方法是直接在对象上调用pandas绘制代码:
fig, axes = plt.subplots(4, 1, sharex=True)
decomposition.observed.plot(ax=axes[0], legend=False, color='r')
axes[0].set_ylabel('Observed')
decomposition.trend.plot(ax=axes[1], legend=False, color='g')
axes[1].set_ylabel('Trend')
decomposition.seasonal.plot(ax=axes[2], legend=False)
axes[2].set_ylabel('Seasonal')
decomposition.resid.plot(ax=axes[3], legend=False, color='k')
axes[3].set_ylabel('Residual')