### Custom colormaps

From an excellent post here , we have a clear explanation of how to make custom colormaps. Under matplotlib there is a colors module which has a method called LinearSegmentedColormap that can create a colormap for your use.

First you need to make a color dictionary which looks like this:
`cdict = {'red'  :  ((0., 0., 0.), (0.5, 0.25, 0.25), (1., 1., 1.)),'green':  ((0., 1., 1.), (0.7, 0.0, 0.5), (1., 1., 1.)),'blue' :  ((0., 1., 1.), (0.5, 0.0, 0.0), (1., 1., 1.))}`
For each 'primary' additive color (rgb) you have to specify a tuple (...) which inturn is a collection of triples. Each triple defines a pivot point for that color in your color map.

The triple (0.7, 0.0, 0.5) for instance, means for 'green' when the normalized value is just below 0.7 the green component should be 0.0, and just above 0.7 the green component should be 0.5. This of course creates a discontinuity in the map at 0.7. To make a continuous map all the pivot points should have the same value above and below. So the triple (0.5, 0.25, 0.25) for 'red' means for values just above and below .5 the 'red' component will be .25 .

Values in between pivot points are linearly interpolated by the function matplotlib.colors.LinearSegmentedColormap.

A complete (and ugly) example is given below:

`import pylab as mcdict = {'red'  :  ((0., 0., 0.), (0.5, 0.25, 0.25), (1., 1., 1.)),'green':  ((0., 1., 1.), (0.7, 0.0, 0.5), (1., 1., 1.)),'blue' :  ((0., 1., 1.), (0.5, 0.0, 0.0), (1., 1., 1.))}#generate the colormap with 1024 interpolated valuesmy_cmap = m.matplotlib.colors.LinearSegmentedColormap('my_colormap', cdict, 1024)#create a gaussianx = m.arange(0, 50 , 1 , m.Float)y = x[:,m.NewAxis]x0 = y0 = x.size // 2fwhm= x0/1.2z = m.exp(-4*m.log(2)*((x-x0)**2+(y-y0)**2)/fwhm**2)pcolormesh(z, cmap = my_cmap)colorbar()`
The api is more for reference, rather than learning.

1. Thank you very much...you have very clearly explained what I was struggling to learn from terser sources.

Paul

### Python: Multiprocessing: passing multiple arguments to a function

Write a wrapper function to unpack the arguments before calling the real function. Lambda won't work, for some strange un-Pythonic reason.

import multiprocessing as mp def myfun(a,b): print a + b def mf_wrap(args): return myfun(*args) p = mp.Pool(4) fl = [(a,b) for a in range(3) for b in range(2)] #mf_wrap = lambda args: myfun(*args) -> this sucker, though more pythonic and compact, won't work p.map(mf_wrap, fl)

### Flowing text in inkscape (Poster making)

You can flow text into arbitrary shapes in inkscape. (From a hint here).

You simply create a text box, type your text into it, create a frame with some drawing tool, select both the text box and the frame (click and shift) and then go to text->flow into frame.

UPDATE: