python - 如何更改 Statsmodel 分解图中折线图的颜色
问题描述
季节性分解图的默认颜色是浅蓝色。1. 如何改变颜色,让每条线都是不同的颜色?2.如果每个情节不能有单独的颜色,我将如何将所有颜色更改为红色?
我尝试向分解.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
对象在绘图方法中使用熊猫。我没有看到将颜色直接传递给方法的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')
推荐阅读
- javascript - 是否可以通过网络查询苹果电视上正在播放的内容,最好是通过 JS 查询?
- firebase - 在 Firestore 规则中的通配符前添加文本
- microsoft-teams - Microsoft Teams Graph Explorer:如何在“发送频道消息”API 中提及频道成员?
- swift - 从另一个未在 | 中声明的类修改 @Published 变量 SwiftUI
- airflow - 定义气流中的维护窗口
- r - 如何创建一个新的因子水平来汇总其他因子水平的总值?
- xamarin.forms - Xamarin App 在等待 GetAsync 方法后什么也不做
- react-native - 第二次执行应用程序 React Native 时出错
- azure - 在 dogfood 环境中创建权限帐户时始终处于验证状态
- excel - Excel - 二维条形图 - 更改水平轴标签