Closed jcursons closed 5 months ago
I've done a bit more debugging/testing and it seems that the issue arises due to my habit of plotting large multipanel figures.
If I run this, it works:
waltons = load_waltons()
handFig = plt.figure(figsize=(5,5))
handAx= handFig.add_axes([0.1, 0.7, 0.8, 0.2])
kmf = KaplanMeierFitter(label='waltons_data')
kmf.fit(waltons['T'], waltons['E'])
kmf.plot(ax=handAx)
handFig.savefig(os.path.join(PathDir.pathOut, 'test.png'), dpi=300)
plt.close(handFig)
But if I try to add a second axis to the figure, it crashes with the error listed above:
waltons = load_waltons()
handFig = plt.figure(figsize=(5,5))
handAx= handFig.add_axes([0.1, 0.7, 0.8, 0.2])
kmf = KaplanMeierFitter(label='waltons_data')
kmf.fit(waltons['T'], waltons['E'])
kmf.plot(ax=handAx)
handAx2 = handFig.add_axes([0.1, 0.2, 0.8, 0.2])
kmf2 = KaplanMeierFitter(label='waltons_data')
kmf2.fit(waltons['T'], waltons['E'])
kmf2.plot(ax=handAx2)
handFig.savefig(os.path.join(PathDir.pathOut, 'test.png'), dpi=300)
plt.close(handFig)
I suspect that using the built in subplot spec is a bit too smart for my approach of just dropping in axes at specified positions using handFig.add_axes() (even if I specify the axis handle through the ax input parameter)
Hm, is it a pandas thing? We bumped min pandas from 1.0 to 1.2. What version of pandas have you been using?
Yeah, I'm having the same problem. This example shows no plots
from lifelines.statistics import survival_difference_at_fixed_point_in_time_test
from lifelines import KaplanMeierFitter
from lifelines.datasets import load_waltons
df = load_waltons()
ix = df['group'] == 'miR-137'
T_exp, E_exp = df.loc[ix, 'T'], df.loc[ix, 'E']
T_con, E_con = df.loc[~ix, 'T'], df.loc[~ix, 'E']
kmf_exp = KaplanMeierFitter(label="exp").fit(T_exp, E_exp)
kmf_con = KaplanMeierFitter(label="con").fit(T_con, E_con)
point_in_time = 10.
results = survival_difference_at_fixed_point_in_time_test(point_in_time, kmf_exp, kmf_con)
results.print_summary()
kmf_exp.plot_survival_function(point_in_time=point_in_time)
kmf_con.plot_survival_function(point_in_time=point_in_time)
I can copy-paste that snippet into ipython, but I also need to add plt.show
for it to appear.
Apologies for the delayed response, but great suggestion thanks @CamDavidsonPilon - updating pandas from 2.0.1 to 2.2.0 has fixed the issue that I was having!
yup, all working here too. Thanks for the quick response.
Hi,
I've recently updated lifelines and it has broken all of my previous plotting functions. Unfortunately I can't even seem to get your test code working, as per https://lifelines.readthedocs.io/en/latest/fitters/univariate/KaplanMeierFitter.html
This gives the error:
I get a similar error when I try run my (previously working) functions on my own data.
The actual point of failure appears to be line 919 in plotting.py:
If I run up to this point and check some of the objects in memory everything appears to be in order:
But it still falls over:
Despite using python for a number of years I struggle to 'read' lambda functions in my head, so unfortunately I don't even know where to start with fixing this unless I start replacing large code chunks