Make `util.plot_gp_dist` transparency-proof
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 9.8k
- Forks
- 2.3k
- Avg merge
- 21h 39m
- Merged PRs (30d)
- 5
Description
Description of your problem
The plot_gp_dist function handles fill_alpha in a weird way (at least to me):
for i, p in enumerate(percs[::-1]):
upper = np.percentile(samples, p, axis=1)
lower = np.percentile(samples, 100 - p, axis=1)
color_val = colors[i]
ax.fill_between(x, upper, lower, color=cmap(color_val), alpha=fill_alpha, **fill_kwargs)
Because the region between 1% and 99% and the region between 2% and 98% overlap, the fill_alpha parameter might not have the intended effect. The stacking of multiple transparent regions will result in the center percentiles not having transparency at all? There are 40 semi-transparent rectangles stacked in the center. The stacking of colors and color mixing might also distort the colormap towards the center.
Test-Graphs using rtcovidlive/rtlive-global with dataset from here, but heavily cropped.
What it looks like now (fill_alpha=0.6):

When setting fill_alpha=0.6, fill_kwargs={"edgecolor":"none"} the hard lines disappear or get softer. Still not 60% transparent:

What i expected (modified code with fill_alpha=0.6, fill_kwargs={"edgecolor":"none"}):

Code replacing these lines:
cmap = plt.get_cmap(palette)
N = 81
percs = np.linspace(1, 99, N)
colors = 1 - np.abs(percs - 50) / (np.max(percs) - 50)
samples = samples.T
x = x.flatten()
percs_bounds = np.percentile(samples, percs, axis=1)
for i, p in enumerate(percs[:(N-1)//2]):
color_val = colors[i]
ax.fill_between(x, percs_bounds[i], percs_bounds[i + 1], facecolor=cmap(color_val), alpha=fill_alpha, edgecolor="none", **fill_kwargs)
ax.fill_between(x, percs_bounds[-i-1], percs_bounds[-i-2], facecolor=cmap(color_val), alpha=fill_alpha, edgecolor="none", **fill_kwargs)
if N % 2 == 0:
ax.fill_between(x, percs_bounds[N//2 - 1], percs_bounds[N//2], facecolor=cmap(1.0), alpha=fill_alpha, edgecolor="none", **fill_kwargs)
Fixing or changing this behavior has to be considered a BC-break, I guess. But maybe I'm also missing something and this style of "progressive transparency" was intended?
Versions and main components
- PyMC3 Version: 3.11.2
- Aesara Version: ?
- Python Version: 3.8.8
- Operating system: Windows 10
- How did you install PyMC3:
conda env create -fenvironment.yml
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in pymc3/gp/util.py at plot_gp_dist, especially the fill_alpha handling around lines 152-161. Reproduce the overlapping percentile regions with fill_alpha=0.6 and the reported edgecolor setting, then compare the result with the expected graph in the issue. Done means the transparency and color behavior is resolved or explicitly defined, with the backward-compatibility impact addressed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- matplotlib, python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100