My setup: Running Python (Python 3.9.16 64-bit) using Jupyter Notebook inside Spyder 5.3.3 on Linux Mint 21
What I do:
First cell: imports (Pandas, GeoPandas, seaborn, matplotlib, ...)
Second cell: Import a gpkg into a gdf
Third cell: using some parameters to create multiple new gdf with extracts from the first one. They are each saved as an entry in a df so I can automatically access them in a Loop (I later want to be able to do my analyses automatically on different sets of smaller gdf).
Fourth cell: writing the important bits of information from the two gdf into a df in long format. Then I create a plot with a combination of seaborn boxplot and barplot. Barplot is only used to show an errorbar on top of the boxplot using this code:
### add CI
ax2= sns.barplot(
data=df_plot, x='bez', y="distance_overtaker",
#palette="Blues",
order = pos2,
alpha=0.0,
capsize=.1, n_boot=1000,
errorbar=('ci', 95),
errcolor= 'red', #errcolor='.26' =
errwidth=0.7,
ax=ax)
Fith cell: Create a different plot from the two gdf (directly, not using the df from above) using seaborn regplot:
for i, row in liste.iterrows():
sns.regplot(x=krit, y='distance_overtaker', data=row['gdf'], fit_reg=True, x_jitter=0, ci=95, ax=ax, scatter_kws={'alpha':1., 's':1}, label=row['bez'])
When I execute the fourth cell the output may look like either of the following images: Barplot Pic 1 Barplot Pic 2
You may notice that the right errorbar is different. This may or may not happen every time I execute the cell again. I could not find an regularity in it yet.
When I execute the fith cell the error bands look slightly different every time I execute the cell. There seem to be lots of variations. Two examples look like this: Regplot Pic 1 Regplot Pic 2
Has anyone got an explanation as to why this might happen?
The reason for the fluctuating results is due to the bootstrap estimation of the confidence interval. If not all samples are used, this technique will converge to the confidence interval, but will not be exact.
Further details are explained in this question.
For the fourth cell with sns.barplot
, increasing the value of n_boot
will increase the stability of the value. Same goes for the fifth cell and sns.regplot
, just add an n_boot
parameter and increase it beyond 1000 (at the cost of computing speed).
Another option would be to fix the seed via the seed
parameter:
seed: Seed of random number generator for reproducible bootstrapping