I have a matplotlib.path.Path object. How do I render it to bitmap (or array with color values).
I quess I have to use the backend/rendere to draw the object but how do I do that?
Edit:
Most of matplotlib's drawable objects (markers, axes, etc) are in vector format. These objects are subclasses of Path. I want to render these to bitmaps in other words rasterize them.
Example: I draw a circular marker 'bo'. What do I need to do to get a bitmap of one circular marker? I cannot just draw a circle and color it blue. I want to get any marker from a plot and get the bitmap of that. Just that one marker with correct color, shape and size and all other attributes. Also no background or foreground or any other element should not be in the figure. This case is similar how the legend draws its symbols. How do I do that?
Here is a hack how to get it to work. Basically create an empty figure and draw the Path in the center to that canvas. Then get the canvas as string. Then take the center of that figure. I'll accept this until a better solution comes my way. In the code below X is an array containing the rasterized symbol. Below is a figure showing the rasterized symbol.
from matplotlib.backends.backend_agg import FigureCanvasAgg
from matplotlib.figure import Figure
import numpy
import pylab
# create figure and draw symbol with three points
fig = Figure(figsize=(5,4), dpi=600)
ax = fig.add_subplot(111)
ax.plot([0,1,2],[0,0,0], '-o', mec='b', mfc='g')
# get canvas, draw and get as string
canvas = FigureCanvasAgg(fig)
canvas.draw()
s = canvas.tostring_rgb()
# convert to array
l,b,w,h = fig.bbox.bounds
w, h = int(w), int(h)
X = numpy.fromstring(s, numpy.uint8)
X.shape = h, w, 3
# plot only the center as bitmap
pylab.imshow(X[h/2-50:h/2+50, w/2-0:w/2+80,:])
pylab.show()