Add 'band' mode for errorbars#581
Conversation
| else: | ||
| raise ValueError(f"Invalid errorbar mode: {mode}") | ||
|
|
||
| def update(self, x: np.ndarray, y: np.ndarray, e: np.ndarray, hist: bool) -> None: |
There was a problem hiding this comment.
There is some repeated code in this function and __init__. Can you extract it?
| self._artist.remove() | ||
| self._artist = self._ax.fill_between( | ||
| x, yme, ype, color=color, alpha=alpha, zorder=zorder, **extra_arg | ||
| ) |
There was a problem hiding this comment.
I guess you checked and this artist cannot be modified in place?
There was a problem hiding this comment.
You can but it gets annoying when you have to handle both the line and step case. In the line case, the vertices are made of len(x)*2 + 3 points (don't ask why +3) but in the step case it's len(x)*4 + 3.
To replace the vertices you have to use a mix of ordered points and points in reverse order, and with the step you have to insert some np.repeat in there as well.
I decided for the sake of simplicity to just remove and re-create. Performance seems fine on what I tested (although I could have tested on larger data; i will do that now just to make sure).
There was a problem hiding this comment.
Turns out it is noticeably slower with larger data 😞. I will try to update in-place.
| if data.variances is not None: | ||
| error = { | ||
| 'x': np.asarray(sc.midpoints(x).values) if hist else xvalues, | ||
| 'x': xvalues, # np.asarray(sc.midpoints(x).values) if hist else xvalues, |
There was a problem hiding this comment.
Should this commented code be removed?
| xverts = np.concatenate([x[0:1], x2, x2[::-1][1:], x[0:1]]) | ||
| a = np.repeat(yme, 2) | ||
| b = np.repeat(ype, 2)[::-1] | ||
| yverts = np.concatenate([[b[-1]], a[0:1], a, b[0:1], b, b[-2:]]) |
There was a problem hiding this comment.
This does indeed look complicated. But it seems to make sense.
There was a problem hiding this comment.
I hope the interface/number of vertices doesn't randomly change when they release a new matplotlib...
We expand the scope of the

errorbarsargument from being justTrue/Falseto also accepting a string to control the mode for representing errorbars on 1d plots. This can now be a'band'which plots as:Example:
Fixes #580