Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect errobar for drawstyle='steps-post' #3702

Open
MLopez-Ibanez opened this issue May 31, 2024 · 2 comments
Open

Incorrect errobar for drawstyle='steps-post' #3702

MLopez-Ibanez opened this issue May 31, 2024 · 2 comments

Comments

@MLopez-Ibanez
Copy link

Plotting an errorbar for several step functions draws the error bars ignoring the steps:

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
data = pd.DataFrame({
    "iteration" : [ 1, 3, 8,  1, 3, 8,  1, 3, 8],
    "value"     : [10, 9, 8, 11, 6, 5, 20, 5, 4],
    "run"       : [1,  1, 1,  2, 2, 2,  3, 3, 3],
})
sns.lineplot(data=data, x='iteration', y='value', errorbar='sd',drawstyle='steps-post')
plt.show()

image

It should be something like this:

image

using R:

library(ggplot2)
library(pammtools)
data <- read.table(header=TRUE, text='
   iteration  value  run
          1     10    1
          3      9    1
          8      8    1
          1     11    2
          3      6    2
          8      5    2
          1     20    3
          3      5    3
          8      4    3
')
ggplot(data, aes(x=iteration, y=value)) +
  geom_step(stat = "summary", fun = mean) +
  stat_summary(geom='stepribbon', 
    fun.data = mean_se, alpha = 0.5)  # added transparency

Step functions arise in many real-world scenarios. See a more complicated example here: https://adibender.github.io/pammtools/reference/geom_stepribbon.html#examples

@mwaskom
Copy link
Owner

mwaskom commented May 31, 2024

I don't think this is a bug really, just a consequence of lineplot accepting all of the parameters for the underlying matplotlib plot function, which has a vast functionality. So this is a feature request for lineplot, but probably not one that would get added any time soon.

@MLopez-Ibanez
Copy link
Author

MLopez-Ibanez commented May 31, 2024

I don't think this is a bug really, just a consequence of lineplot accepting all of the parameters for the underlying matplotlib plot function, which has a vast functionality. So this is a feature request for lineplot, but probably not one that would get added any time soon.

I can edit the title to mention Feature Request if you wish.

Step functions are so common (timeseries, ECDFs, survival analysis, inventory levels, etc) that they may warrant a dedicated function stairplot() function. Perhaps this feature request may inspire someone not willing to use R to implement it (or may tell people looking for this feature how to do it in R).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants