意外绘图-将预测间隔绘制为阴影区域

时间:2019-04-03 16:15:40

标签: python python-3.x matplotlib

我正在尝试在此answer中复制橙色图。 我有以下数组:

test-labels作为真实值(x轴); predictions作为预测值(蓝色叉号)

y_upper作为第95个百分点的预测值(红色x标记); y_lower作为第5个百分位数的预测值(黑色x标记)

Plot of arrays for reference

尝试复制1中的阴影区域:

plt.figure()
plt.plot(test_labels, predictions, 'b-')
plt.fill_between(test_labels, y_lower, y_upper, alpha=0.5, edgecolor='#CC4F1B', facecolor='#FF9848')
plt.show()

但是我得到了这个plot。关于这有什么问题的任何想法吗?

编辑:即使使用新数组,仍会得到unexpected results。下面的代码

import matplotlib.pyplot as plt
import random

test_labels = random.sample(range(0, 30), 10)
predictions = [x+random.uniform(-0.9, 0.9) for x in test_labels]
y_upper = [x+3 for x in test_labels]
y_lower = [x-3 for x in test_labels]

plt.figure()
plt.plot(test_labels, predictions, 'b-')
# plt.plot(test_labels, y_upper, 'rx')
# plt.plot(test_labels, y_lower, 'kx')

plt.fill_between(test_labels, y_lower, y_upper, alpha=0.5, edgecolor='#CC4F1B', facecolor='#FF9848')
plt.show()

0 个答案:

没有答案
相关问题