1

I have recently reinstalled my OSX, Python and all my dependencies but when running old code that used to work (see question: Wrong offset when using math mode and subscripts in Matplotlib and OSX) is now throwing an exception and a segmentation fault. The full code is in the linked question and there have been no changes. This is the error I am getting:

  File "matplotlib-stacked.py", line 57, in <module>
    plt.stackplot(NP.arange(num_cols)+1,data,colors=colors)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 3326, in stackplot
    ret = ax.stackplot(x, *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1811, in inner
    return func(ax, *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/axes/_axes.py", line 4439, in stackplot
    return mstack.stackplot(self, x, *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/stackplot.py", line 66, in stackplot
    axes.set_color_cycle(colors)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/axes/_base.py", line 1126, in set_color_cycle
    self.set_prop_cycle('color', clist)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/axes/_base.py", line 1112, in set_prop_cycle
    prop_cycle = cycler(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/rcsetup.py", line 720, in cycler
    vals = validator(vals)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/rcsetup.py", line 90, in f
    raise ValueError(msg)
ValueError: 's' must be of type [ string | list | tuple ]
Segmentation fault: 11

I have no clue where to look at, anyone familiar with matplotlib has ever encountered this problem? The python launcher seems to try to open the interactive plot window but then I get the segmentation fault.

Community
  • 1
  • 1
Josep Valls
  • 5,483
  • 2
  • 33
  • 67
  • My past self did not take notes of all the module versions I was using but I am now on OSX 10.11 and Python 2.7.10 using the wxPython installed via brew (stable 3.0.2.0) and the Matplotlib installed via pip (matplotlib==1.5.0). – Josep Valls Feb 09 '16 at 22:06
  • Maybe you should try another ["packed-and-ready-to-go"](https://wiki.python.org/moin/PythonDistributions) python distribution that includes matplotlib and/or scipy s.a. [Anaconda](https://www.continuum.io/downloads) or [Enthought Canopy](https://store.enthought.com/). Not to shut down your efforts, but I've been in that "can't handle all these binaries" and these have worked out all right for me. Keep an eye on licenses. – Felipe Lema Feb 10 '16 at 12:26
  • @FelipeLema thanks for your advice. Since I reinstalled I've been using brew and pip to handle all my dependencies (unlike before when I often downloaded and installed packages myself). I was hoping pip freeze will help me document my projects for the future. – Josep Valls Feb 10 '16 at 16:07

1 Answers1

1

I found actually TWO workarounds:

I managed to isolate the problem to the colors passed to the stackplot method. Turns out that matplotlib.pyplot.stackplot doesn't play nicely with the colors given by matplotlib.cm.rainbow helper. Converting the colors from RGBA to hex solved the problem.

colors = cm.rainbow(NP.linspace(0, 1, num_cols))
colors = [matplotlib.colors.rgb2hex(i) for i in colors]

Then I noticed that I was not using the latest version of matplotlib. Upgrading from 1.5.0 to 1.5.1 also solved the issue (regardless of the color format being used).

I hope this helps anyone who encounters the same cryptic problem or cannot upgrade matplotlib.

Josep Valls
  • 5,483
  • 2
  • 33
  • 67