to_numeric.py

来自「非原创。很好的python例子」· Python 代码 · 共 31 行

PY
31
字号
#!/usr/bin/env python"""Use backend agg to access the figure canvas as an RGB string and thenconvert it to a Numeric array and pass the string it to PIL forrendering"""from pylab import *from matplotlib.backends.backend_agg import FigureCanvasAggplot([1,2,3])canvas = get_current_fig_manager().canvasagg = canvas.switch_backends(FigureCanvasAgg)agg.draw()s = agg.tostring_rgb()  # get the width and the height to resize the matrixl,b,w,h = agg.figure.bbox.get_bounds()w, h = int(w), int(h)X = fromstring(s, UInt8)X.shape = h, w, 3import Imageim = Image.fromstring( "RGB", (w,h), s)im.show()

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?