I have some data stored as [samples, x_values_toconsider]
and then I give it to seaborn. I've tried many combinations for it to plot the error bands but it doesn't seem to do it, it simply plots each of my samples for a specific feature/value of x. So it ends up have samples
number of curves, which is NOT what I want. I've also tried to arrange it as a data frame but that didn't help either.
Why is seaborn plotting each individual sample as it's own curve? I want it to aggregate it with the usual confidence intervals.
Self contained Reproducible code:
#%%
"""
https://seaborn.pydata.org/tutorial/relational.html#relational-tutorial
https://seaborn.pydata.org/examples/errorband_lineplots.html
https://www.youtube.com/watch?v=G3F0EZcW9Ew
https://github.com/knathanieltucker/seaborn-weird-parts/commit/3e571fd8e211ea04b6c9577fd548e7e532507acf
https://github.com/knathanieltucker/seaborn-weird-parts/blob/3e571fd8e211ea04b6c9577fd548e7e532507acf/tsplot.ipynb
"""
from collections import OrderedDict
import numpy as np
import seaborn as sns
from matplotlib import pyplot as plt
from pandas import DataFrame
import pandas as pd
print(sns)
np.random.seed(22)
sns.set(color_codes=True)
# the number of x values to consider in a given range e.g. [0,1] will sample 10 raw features x sampled at in [0,1] interval
num_x: int = 10
# the repetitions for each x feature value e.g. multiple measurements for sample x=0.0 up to x=1.0 at the end
rep_per_x: int = 5
total_size_data_set: int = num_x * rep_per_x
print(f'{total_size_data_set=}')
# - create fake data set
# only consider 10 features from 0 to 1
x = np.linspace(start=0.0, stop=1.0, num=num_x)
# to introduce fake variation add uniform noise to each feature and pretend each one is a new observation for that feature
noise_uniform: np.ndarray = np.random.rand(rep_per_x, num_x)
# same as above but have the noise be the same for each x (thats what the 1 means)
noise_normal: np.ndarray = np.random.randn(rep_per_x, 1)
# signal function
sin_signal: np.ndarray = np.sin(x)
# [rep_per_x, num_x]
data: np.ndarray = sin_signal + noise_uniform + noise_normal
# data_od: OrderedDict = OrderedDict()
# for idx_x in range(num_x):
# # [rep_per_x, 1]
# samples_for_x: np.ndarray = data[:, idx_x]
# data_od[str(x[idx_x])] = samples_for_x
#
# data_df = pd.DataFrame(data_od)
# data = data_df
print(data)
ax = sns.lineplot(data=data)
# ax = sns.lineplot(data=data, err_style='band')
# ax = sns.lineplot(data=data, err_style='bars')
# ax = sns.lineplot(data=data, ci='sd', err_style='band')
# ax = sns.lineplot(data=data, ci='sd', err_style='bars')
# ax = sns.relplot(data=data)
plt.show()
#%%
"""
https://seaborn.pydata.org/examples/errorband_lineplots.html
"""
# import numpy as np
# import seaborn as sns
# from matplotlib import pyplot as plt
# from pandas import DataFrame
#
# fmri: DataFrame = sns.load_dataset("fmri")
# print(fmri)
# sns.lineplot(x="timepoint", y="signal", hue="region", style="event", data=fmri)
# plt.show()
wrong plot produce
but hoped for something like this (and with addition lines with their own error bands would be even better cuz I have many matrices!)
like:
Note that I do not want to pre-calculate the stds and plot the bands so most of those questions/answers don't work for me.
What puzzles me is that when I pass it the fmri data it works but not when I pass it my matrix of observations for each x value...
related posts:
- How to use custom error bar in seaborn lineplot
- Draw error shading bands on line plot - python
- How to make the confidence interval (error bands) show on seaborn lineplot
- https://github.com/knathanieltucker/seaborn-weird-parts/blob/3e571fd8e211ea04b6c9577fd548e7e532507acf/tsplot.ipynb
- https://www.youtube.com/watch?v=G3F0EZcW9Ew
- https://seaborn.pydata.org/examples/errorband_lineplots.html