2

I try to use pythons lifelines package Package website and Github. After trying to run the example from the website which reads:

from lifelines.datasets import load_waltons
from lifelines import KaplanMeierFitter    
df = load_waltons()
T = df['T']
E = df['E']
kmf = KaplanMeierFitter()
kmf.fit(T, event_observed=E)
kmf.plot()

Resulting in the following error

Traceback (most recent call last):
File "/Kaplan_Meier/Kaplan_Meier.py", line 11, in <module>
kmf.plot()
File "/lib/python3.5/site-packages/lifelines/plotting.py", line 331, in plot
set_kwargs_color(kwargs)
File "/lib/python3.5/site-packages/lifelines/plotting.py", line 223, in set_kwargs_color
kwargs["ax"]._get_lines.get_next_color())
AttributeError: '_process_plot_var_args' object has no attribute 'get_next_color'

I feel like I am missing out on something, but cant really work out, what is going wrong. Any help is appreciated.

The plotting function is wrapped around Pandas and I use python 3.5.4. EDIT: Pandas is version 0.21.0 which should work as 0.18 or above is required according to https://pypi.python.org/pypi/lifelines/0.12.0

Mohamed Thasin ah
  • 10,754
  • 11
  • 52
  • 111
hhlw
  • 97
  • 1
  • 7

1 Answers1

1

Update matplotlib to >= 2.0!

If you look at the blame view for the line of code that bugs you, you can see it was last changed when CamDavidsonPilon bumped the required matplotlib version to 2.0 about 3 months ago. In the same commit, he removed some code that supported versions of matplotlib that don't have get_next_color.

thorbjornwolf
  • 1,788
  • 18
  • 19
  • Thanks! Fixed the issue, will make sure to cover the whole github histroy myself the next time! – hhlw Nov 23 '17 at 14:22
  • 1
    You're welcome :) Hehe, don't strain yourself! I hope the answer didn't give the impression that you should totally have seen that yourself. The git blame approach just happened to be helpful here. – thorbjornwolf Nov 23 '17 at 14:43
  • Author here: how did @hhlw have the latest lifelines _without_ the latest matplotlib? I thought requirements.txt would tell `pip` to install the latest matplotlib. – Cam.Davidson.Pilon Dec 08 '17 at 04:46
  • I don't know how I ended up without the latest matplotlib, I just just recreated the whole set-up, with a new virtual environment and checked the packages installed by lifelines and again I ended up with all packages (pandas, numpy...) but not matplotlib (no matplotlib at all). I am using PyCharm. Let me know if you need/want detailed information. – hhlw Dec 08 '17 at 11:34