python - 在 pyplot 中使用 fill_between() 绘图
问题描述
我无法绘制模型预测周围的区域,我认为使用 fill_between 绘图会很简单。
对于一个可重现的例子:
df1
Ground_Truth Predictions Predictions_hi Predictions_lo
410 15.0 14.810122 18.356809 11.263436
85 26.6 27.131472 28.320380 25.942565
280 45.4 45.404620 47.274549 43.534691
422 20.8 19.081849 20.711096 17.452601
199 34.9 29.703281 32.416996 26.989566
364 21.9 49.010702 52.162232 45.859172
5 28.7 27.330305 29.026654 25.633956
415 7.2 8.412145 10.244244 6.580046
209 20.0 17.257462 19.459939 15.054985
284 32.2 28.166823 30.390787 25.942859
json格式的数据:
{"Ground_Truth":{"410":15.0,"85":26.6,"280":45.4,"422":20.8,"199":34.9,"364":21.9,"5":28.7,"415":7.2,"209":20.0,"284":32.2},"Predictions":{"410":14.8101220869,"85":27.1314724323,"280":45.4046198732,"422":19.0818488429,"199":29.7032811382,"364":49.0107021787,"5":27.3303047283,"415":8.4121453666,"209":17.2574622383,"284":28.1668228107},"Predictions_hi":{"410":18.3568086485,"85":28.3203798966,"280":47.2745488681,"422":20.7110962223,"199":32.4169963433,"364":52.1622320467,"5":29.0266538906,"415":10.2442444504,"209":19.4599393417,"284":30.3907868523},"Predictions_lo":{"410":11.2634355254,"85":25.9425649679,"280":43.5346908782,"422":17.4526014635,"199":26.989565933,"364":45.8591723107,"5":25.6339555659,"415":6.5800462828,"209":15.054985135,"284":25.9428587691}}
我的代码如下:
results_df1.plot(x= 'Ground_Truth', y = 'Predictions', kind = 'scatter', color = 'r')
plt.plot(results_df1['Ground_Truth'],results_df1['Ground_Truth'], color = 'b')
plt.fill_between(results_df1['Ground_Truth'], results_df1['Predictions_lo'], results_df1['Predictions_hi'], alpha = 0.1)
plt.show()
此代码返回以下图:
你看到了我没想到的jig-jag。
解决方案
推荐阅读
- python - 无法将烧瓶数据发送到数据库
- mysql - 如何在 localhost mac 上安装 mysql 服务器和 phpmyadmin
- json - 在 Post 方法响应中获取 ID,并且 ID 是自动生成的
- r - 选择一系列列并添加到向量的快捷方式
- c# - 500内部服务器错误。CORS
- php - Codeigniter 从结果行()中获取 2 列
- c# - 检查接口中的对象是否具有值时出现 InvalidOperationException
- java - Kubernetes:将证书填充到密钥库中
- javascript - 根据 React 中多维数组中的数据渲染组件
- javascript - 如何在用户上传的图像上添加标记?