我有一个图表,将贝叶斯平均点数据绘制在一条线上,并在平均值周围有可信的间隔。
我正在尝试用半透明颜色填充两条可信线之间,以便平均线真正弹出。我尝试过以下方法:
plt.fill_between(b.get_data(), c.data_get(), color='blue', alpha = .5)
Run Code Online (Sandbox Code Playgroud)
我正在从推理集中提取这些数据arviz。这是一个玩具数据集。
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
mean = np.array([861.98525 , 705.23875 , 640.14575 , 658.727625, 728.23775 ,
792.4645 , 803.045375, 763.425875, 721.785375, 713.182375,
740.543375, 781.466875])
confidence1 = np.array([788. , 607. , 493. , 443.975, 435.975, 412. , 366.975,
295. , 243. , 207. , 181. , 161. ])
confidence2 = np.array([ 938. , 811. , 815. , 935.025, 1150.025, 1391.05 ,
1556.05 , 1624.05 , 1689.025, 1829. , 2078.125, 2390.025])
date = list(df_sat_test['t'].unique())
fig = plt.figure(figsize=(15,4))
a=sns.lineplot(x =date, y = mean, label = 'Posterior Predictive')
b=sns.lineplot(x =date, y = confidence1, label = 'Confidence', color = 'r')
c=sns.lineplot(x =date, y = confidence2, label = 'Confidence', color = 'r')
# plt.fill_between(b.get_data(), c.data_get(), color='blue', alpha = .5)
sns.scatterplot(x =df_sat_test['t'], y = np.array(test_ppc.observed_data.obs), label = 'True Value')
plt.legend()
Run Code Online (Sandbox Code Playgroud)
如果获得最后一个折线图,您将获得三个折线图的数据,您可以将其设置为填充 x 轴和 y 轴的第一个以及填充 y 轴的第二个,以获得预期结果。
fig = plt.figure(figsize=(15,4))
a=sns.lineplot(x=date, y=mean, label = 'Posterior Predictive')
b=sns.lineplot(x=date, y=confidence1, label='Confidence', color='r')
c=sns.lineplot(x=date, y=confidence2, label='Confidence', color='r')
line = c.get_lines()
plt.fill_between(line[0].get_xdata(), line[1].get_ydata(), line[2].get_ydata(), color='blue', alpha=.5)
#sns.scatterplot(x =df_sat_test['t'], y = np.array(test_ppc.observed_data.obs), label = 'True Value')
plt.legend()
plt.show()
Run Code Online (Sandbox Code Playgroud)