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
KM at_risk_counts intervals do not align with manually selected plot interval #1184
Comments
Hi @kadufendach, try this: import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from lifelines import KaplanMeierFitter
df = pd.DataFrame({
'durations': [5, 32, 14, 55, 18, 29, 28, 39, 2, 1, 60, 7],
'events': [1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0]})
D = df['durations']
E = df['events']
kmf = KaplanMeierFitter()
kmf.fit(D, E,label="Kaplan-Meier Estimate")
ax = kmf.plot(ci_show=False)
plt.tight_layout()
ax.set_xticks(range(0,61,12))
# now add the table:
from lifelines.plotting import add_at_risk_counts
add_at_risk_counts(kmf, ax=ax)
ax.set_xlabel('Months')
ax.grid(b=True, axis='y')
plt.show() |
Worked perfectly @CamDavidsonPilon, thanks for your help! |
Glad to hear - I'm going to reopen this so it remind me to add a note to the documentation on this. |
Hi @CamDavidsonPilon I'm in a similar situation where I'm passing in the Is it possible to specify the |
Hi @chrispoptic, I'm hestitant to add a new kwarg to
Something like that? |
I am trying to generate a K-M curve over 60 months with interval 12 (instead of 10, which is automatically selected). As demonstrated below, at_risk_counts do not align with 12 month intervals which I've manually set using set_xticks.
Example code is as follows:
I have also tried adding timeline=range(0,61,12) to kmf.fit, but this does not change the at_risk_counts interval. For ex:
Thank you in advance for any help.
The text was updated successfully, but these errors were encountered: