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

add_at_risk_counts moves grid to the front when using seaborn #1642

Open
krz opened this issue Oct 23, 2024 · 0 comments
Open

add_at_risk_counts moves grid to the front when using seaborn #1642

krz opened this issue Oct 23, 2024 · 0 comments

Comments

@krz
Copy link

krz commented Oct 23, 2024

Hi,

When I use the default seaborn theme, the grid is in the front. How can I move the white grid lines to the background.
For example:


import pandas as pd
import numpy as np
from lifelines import KaplanMeierFitter
from lifelines.plotting import add_at_risk_counts
import seaborn as sns

sns.set_theme()

# Generate random data for three hypothetical dataframes
np.random.seed(42)

def generate_data(size):
    return pd.DataFrame({
        'duration': np.random.exponential(10, size),
        'event': np.random.binomial(1, 0.5, size),
        'age': np.random.normal(50, 10, size)
    })

df1 = generate_data(100)
df2 = generate_data(100)
df3 = generate_data(100)

dataframes = [df1, df2, df3]

# Kaplan-Meier Estimation
kmf = KaplanMeierFitter()


fitters = [
    KaplanMeierFitter().fit(
        df['duration'],
        event_observed=df['event'],
        label=f'DataFrame {idx}'
    )
    for idx, df in enumerate(dataframes, 1)
]

for fitter in fitters:
    ax = fitter.plot()

add_at_risk_counts(*fitters, ax=ax)

image

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

1 participant