After a lot of digging and trial and error troubleshooting, I have resolved the issue myself. This answer is specifically for the OS and software/package versions specified in the original question.
Blender 2.79 comes with Python 3.5.3 and Numpy 1.11.2 bundled with it. Other Python packages (e.g. SciPy, matplotlib) are not bundled with Blender.
Install Python 3.5 using Macports, along with the appropriate matplotlib (and any other packages you want to add to Blender) then copy the desired packages from the Macports location to the Blender location.
You can keep python 2.7 as the default python for your system, and set python 3.5 as default for python3 commands:
sudo port select --set python python27
sudo port select --set python3 python35
For me the location of matplotlib in the Macports install is:
And the location that Blender accesses is:
Note that the README file at this location states:
This directory exists so that 3rd party packages can be installed here. Read the source for site.py for more details.
(Confirming that we have the right location)
So, to copy Macports matplotlib package(s) to Blender:
cp -r /opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib /Applications/Blender/blender.app/Contents/Resources/2.79/python/lib/python3.5/site-packages/
You will probably want to copy numpy over as well (replace the existing one bundled with Blender), because the matplotlib you just installed with Macports was compiled with a newer version of numpy (
1.13.3) rather than what is bundled with Blender (
1.11.2). Matplotlib won't play well with the older version of numpy.
There are some additional packages that Blender needs in order to use matplotlib:
These should be copied from and to the same locations specified above for matplotlib.
(See also this post by avocadohead:
(You can take my word for it, or avocadohead's, or you can find these dependencies yourself by trying to plot from the python console in Blender - you will get an import error telling you what it can't find. Then just keep copying over what Blender said it was looking for until the import errors stop).
Note: if you ever update Blender, the above process must be repeated (unless a new version of Blender fixes the issue by bundling these packages)
But there is also an issue with the backend. Start Blender from the terminal so you can see what is going on behind the scenes (I recommend doing this from the beginning actually, because it provides answers a lot of the originally posted questions above regarding the versions and locations of python modules/packages used by Blender). When you try to plot something using the 'Plot' button in 'Plot Output Settings' in CellBlender, you will see the following error in the terminal:
RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.
We can fix this by changing the backend. I recommend Qt4Agg. But Qt4Agg requires an additional module, either PyQt4 or PySide. Blender will only work with PySide. So install py35-pyside using Macports, and copy it over to the Blender location as described above for matplotlib and the other packages.
Now we just need to make this the default backend for matplotlib in Blender. This is done by editing the matplotlibrc file. For me, the Blender matplotlibrc file is found here:
Open it in your favorite editor and change backend from
then uncomment the line
backend.qt4 : PyQt4 and change
PyQt4 in that line to
Now, (finally) when you try to plot something using the 'Plot' button in 'Plot Output Settings' in CellBlender, you will get a plot (and it is in a separate window)!
Other useful posts that helped me get to the bottom of this:
Using 3rd party Python modules
Also, don't bother registering with mmbios.org with the intention of asking urgent questions on their forum - the administrator will take days (still counting) to activate your account, if they activate it at all.