PlotShape colormap

Using the graphical user interface to build and exercise models. Includes customizing the GUI by writing a little bit of hoc.
Post Reply
bschneiders
Posts: 34
Joined: Thu Feb 02, 2017 11:30 am

PlotShape colormap

Post by bschneiders » Tue Apr 07, 2020 11:27 am

Hi, is there are way to make PlotShapes have different colormaps? I changed the color scheme for one plotshape (for fluorescence - I want it to be a single hue) and it ended up changing the rest of them. Is there any way around this, or is colormap a global setting? Thanks!

Also, my method for doing this was pretty clunky. I saved a list of RGB values from a colorbrewer site, and plugged them in to the colormap line by line. If there is a preferred way to do it that gets around the above issue, please let me know!

Code: Select all

greenlist = [[247,252,245],
             [229,245,224],
             [199,233,192],
             [161,217,155],
             [116,196,118],
             [65,171,93],
             [35,139,69],
             [0,109,44],
             [0,68,27]]
for i in range(len(greenlist)):
    l = [i]+greenlist[i]
    sw4.colormap(*l)

ramcdougal
Posts: 205
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: PlotShape colormap

Post by ramcdougal » Thu Apr 09, 2020 12:31 am

The documentation says that colormaps are local by default. If they're not, maybe you could try explicitly setting/unsetting the global flag when you define the size of your colormap before setting its values.

For what it's worth, you can change the default colormap for all of your plotshapes by editing your nrn.def defaults file. See: https://neuron.yale.edu/neuron/static/d ... ormap.html

Matplotlib has a large selection of colormaps; you can get your colors from there. See https://matplotlib.org/3.1.1/gallery/co ... rence.html for a list of their colormaps and what they look like, and see https://stackoverflow.com/questions/254 ... matplotlib for code for extracting the rgb values from their colormaps.

If you're using NEURON 7.7+, you can have your PlotShape render on a matplotlib figure and use their colormaps directly on a per PlotShape basis with the cmap keyword argument:

Code: Select all

from matplotlib import pyplot, cm
ps = h.PlotShape(list(h.allsec()), False)
ps.scale(-80, 40)
ps.variable('v')
ax = ps.plot(pyplot, cmap=cm.jet)
pyplot.show()
This won't update, of course, but it does generate a 3d image you can rotate, etc.

Post Reply