Created
May 28, 2020 19:00
-
-
Save Barry1/897b0b8f3d9d31f15aaed48849d27df0 to your computer and use it in GitHub Desktop.
plot two columns against each other with local uncertainty bands by windowing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas | |
def plotwithuncertainty(data: pandas.DataFrame, | |
x: str, | |
y: str, | |
windowlen: int = max(10, round(len(data) / 100)), | |
**pltops) -> None: | |
evalobj = data[[x, y]].reset_index().rolling( | |
window=windowlen, center=True, on=x) | |
wrkset = pandas.DataFrame() | |
wrkset.loc[:, 'meanx'] = evalobj[x].mean() | |
wrkset.loc[:, 'meany'] = evalobj[y].mean() | |
wrkset.loc[:, 'stdy'] = evalobj[y].std() | |
wrkset.loc[:, 'lb'] = wrkset['meany'] - 3 * wrkset['stdy'] | |
wrkset.loc[:, 'ub'] = wrkset['meany'] + 3 * wrkset['stdy'] | |
wrkset[['meanx', 'lb', 'meany', 'ub']].sort_values( | |
'meanx').plot(x='meanx', **pltops) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment