如何更改 Statsmodel 分解图中线图的颜色
How to Change Color of Line graphs in Statsmodel Decomposition Plots
季节性分解图的默认颜色是淡蓝色。
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')
季节性分解图的默认颜色是淡蓝色。 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')