I create PNG files of scatterplots with code that, in essence, goes as in the sketch below:
cmap = (matplotlib.color.LinearSegmentedColormap.
from_list(‘blueWhiteRed’, [‘blue’, ‘white’, ‘red’]))
fig = matplotlib.figure.Figure(figsize=(4, 4), dpi=72)
ax = fig.gca()
for marker in ‘o s ^ *’.split():
X, Y, COLOR = zip(*((record.x, record.y, record.level)
for record in data if record.marker == marker))
ax.scatter(X, Y, marker=marker,
c=COLOR, vmin=0, vmax=1, cmap=cmap,
**otherkwargs)
various settings of ticks, labels, etc. omitted
canvas = matplotlib.backends.backend_agg.FigureCanvasAgg(fig)
fig.set_canvas(canvas)
IMPORTANT: the generated figure is not displayed on the screen, but
rather it is output to disk as a PNG file:
canvas.print_png(’/path/to/output/fig.png’)
My question is this:
What do I need to add to the code above to get a vertical colorbar (representing the colormap incmap) along the plot’s right edge?
I word the question in this way because I am not sufficiently facile with Matplotlib to deviate too far from the working code above.
In particular, my code has to be able to produce PNG files non-interactively, so the last line in the code sketch above is really essential.
Thanks in advance!
kj