Best way to implement `fill_between` to display uncertainty?
- 主要語言
- Python
- 星號
- 93.9k
- 分支
- 7.7k
- 平均合併
- 2 天 13 小時
- 30 天內合併 PR
- 4
描述
Hello,
I would like to use something similar to `fill_between` that can be found in matplotlib. This is particularly useful to plot uncertainty.
I came up with a hacky solution but as I'm pretty new to the lib, I was wondering if there was a better way?
My solution (using a Polygon to fill the space between [mean - std, mean + std]:
```python
def fill_between(axes, graphs, color, opacity=1, dt=0.01, x_max=None):
points = []
if x_max is None:
x_max = axes.x_max
x_points = np.arange(axes.x_min, x_max, dt)
for x in x_points:
y = np.min([graph.underlying_function(x) for graph in graphs])
points.append(axes.coords_to_point(x, y))
for x in x_points[::-1]:
y = np.max([graph.underlying_function(x) for graph in graphs])
points.append(axes.coords_to_point(x, y))
filling_graph = Polygon(*points)
filling_graph.set_stroke(color, opacity=opacity)
filling_graph.set_fill(color, opacity=opacity)
return filling_graph
```
In matplotlib, I would do something like:
```python
plt.plot(x, mean, label='mean pred')
plt.fill_between(x, mean + std, mean - std, alpha=0.5)
```
EDIT: if the `stroke_width` could be function of the x value, that would solve this issue
貢獻指南
這個儲存庫沒有索引到貢獻指南
研究方向
查看 manim 的原始碼以了解 graphs 和 polygons 是如何實作的,可能在 manim/mobject/geometry.py 或類似檔案中。使用者的程式碼片段顯示了一個使用 Polygon 的自訂 fill_between。研究 matplotlib 的 fill_between 的運作方式,並將其套用到 manim 的座標系。透過建立一個包含兩個 graphs 的簡單場景並填充它們之間的區域來進行測試。
由索引模型根據 Issue 內容生成。
評估
- 領域
- data-visualization
- Issue 類型
- 功能
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100