擅长:python、mysql、java
<p>为了将图形内容获取为RGB像素值,<code>matplotlib.backend_bases.Renderer</code>需要首先绘制画布的内容。您可以通过手动调用<code>canvas.draw()</code>来完成此操作:</p>
<pre><code>from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
fig = Figure()
canvas = FigureCanvas(fig)
ax = fig.gca()
ax.text(0.0,0.0,"Test", fontsize=45)
ax.axis('off')
canvas.draw() # draw the canvas, cache the renderer
image = np.fromstring(canvas.tostring_rgb(), dtype='uint8')
</code></pre>
<p><a href="http://matplotlib.org/users/artists.html" rel="noreferrer">See here</a>了解有关matplotlib API的更多信息。</p>