为了获得图形内容作为RGB像素值,
matplotlib.backend_bases.Renderer需要首先绘制画布的内容。您可以通过手动调用
canvas.draw():
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvasfrom matplotlib.figure import Figurefig = 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 rendererimage = np.fromstring(canvas.tostring_rgb(), dtype='uint8')
有关matplotlib
API的更多信息,请参见此处。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)