例如,您可以使用以下代码在matplotlib中绘制图像:
%matplotlib inline import matplotlib.pyplot as plt import matplotlib.image as mpimg img=mpimg.imread('image.png') plt.imshow(img)
Bokeh(0.10)有可能是这样的吗?
您可以使用ImageURL
字形(image_url
绘图方法)在本地或从Web加载图像.
from bokeh.plotting import figure, show, output_file output_file('image.html') p = figure(x_range=(0,1), y_range=(0,1)) p.image_url(url=['tree.png'], x=0, y=1) show(p)
一个问题 - 如果您只绘制图像(而不是其他数据),则必须明确设置绘图范围.
这是文档:
http://bokeh.pydata.org/en/latest/docs/reference/models/glyphs.html#bokeh.models.glyphs.ImageURL
早期的答案很有帮助.但是,我想要一个没有任何附加对象的图像选项.因此,添加Bokeh版本0.12.0的答案并删除所有网格,轴和工具栏.
from bokeh.plotting import figure, curdoc from bokeh.models import ColumnDataSource, Range1d bosch_logo = "static/tree.jpg" logo_src = ColumnDataSource(dict(url = [bosch_logo])) page_logo = figure(plot_width = 500, plot_height = 500, title="") page_logo.toolbar.logo = None page_logo.toolbar_location = None page_logo.x_range=Range1d(start=0, end=1) page_logo.y_range=Range1d(start=0, end=1) page_logo.xaxis.visible = None page_logo.yaxis.visible = None page_logo.xgrid.grid_line_color = None page_logo.ygrid.grid_line_color = None page_logo.image_url(url='url', x=0.05, y = 0.85, h=0.7, w=0.9, source=logo_src) page_logo.outline_line_alpha = 0 curdoc().add_root(page_logo)