fig, ax = plt.subplots() ax.plot(RV_5.index, RV_5['RV_5min'], color='black', label='Actual') ax.fill_between(RV_5.index, RV_5['RV_5min'] - forecast_error, RV_5['RV_5min'] + forecast_error, alpha=0.2, color='blue', label='无ps置信区间') ax.fill_between(RV_5.index, conf_int_lower, conf_int_upper, alpha=0.2, color='green', label='有ps置信区间') ax.set_title('Prediction Intervals') ax.set_xlabel('Time') ax.set_ylabel('RV_5min') plt.legend() plt.show() fig, ax = plt.subplots() ax.plot(RV_5.index, RV_5['RV_5min'], color='black', label='Actual') ax.fill_between(RV_5.index, RV_5['RV_5min'] - forecast_error, RV_5['RV_5min'] + forecast_error, alpha=0.2, color='blue', label='无ps置信区间') ax.fill_between(RV_5.index, conf_int_lower, conf_int_upper, alpha=0.2, color='green', label='有ps置信区间') fig, ax = plt.subplots() ax.plot(RV_5.index, RV_5['RV_5min'], color='black', label='Actual') ax.fill_between(RV_5.index, RV_5['RV_5min'] - forecast_error, RV_5['RV_5min'] + forecast_error, alpha=0.2, color='blue', label='无ps置信区间') ax.fill_between(RV_5.index, conf_int_lower, conf_int_upper, alpha=0.2, color='green', label='有ps置信区间') fig, ax = plt.subplots() ax.plot(RV_5.index, RV_5['RV_5min'], color='black', label='Actual') ax.fill_between(RV_5.index, RV_5['RV_5min'] - forecast_error, RV_5['RV_5min'] + forecast_error, alpha=0.2, color='blue', label='无ps置信区间') ax.fill_between(RV_5.index, conf_int_lower, conf_int_upper, alpha=0.2, color='green', label='有ps置信区间') fig, ax = plt.subplots() ax.plot(RV_5.index, RV_5['RV_5min'], color='black', label='Actual') ax.fill_between(RV_5.index, RV_5['RV_5min'] - forecast_error, RV_5['RV_5min'] + forecast_error, alpha=0.2, color='blue', label='无ps置信区间') ax.fill_between(RV_5.index, conf_int_lower, conf_int_upper, alpha=0.2, color='green', label='有ps置信区间') 怎么将两个ax.fill_between画在一幅图上,不相互遮挡,
时间: 2024-01-30 20:02:27 浏览: 105
matplotilb中fig,ax = plt.subplots()的使用
你可以使用相同的 `ax` 对象来绘制多个 `fill_between` 图形,以确保它们在同一幅图上不会相互遮挡。下面是一个示例代码:
```python
fig, ax = plt.subplots()
ax.plot(RV_5.index, RV_5['RV_5min'], color='black', label='Actual')
ax.fill_between(RV_5.index, RV_5['RV_5min'] - forecast_error, RV_5['RV_5min'] + forecast_error, alpha=0.2, color='blue', label='无ps置信区间')
ax.fill_between(RV_5.index, conf_int_lower, conf_int_upper, alpha=0.2, color='green', label='有ps置信区间')
ax.set_title('Prediction Intervals')
ax.set_xlabel('Time')
ax.set_ylabel('RV_5min')
plt.legend()
plt.show()
```
这段代码将在同一幅图中绘制 `Actual` 曲线,并在其上方分别绘制了 `无ps置信区间` 和 `有ps置信区间` 的填充区域,它们不会相互遮挡。注意确保只创建一个 `fig` 和 `ax` 对象,并在同一个 `ax` 对象上调用多个 `fill_between` 方法。
阅读全文