plot image with interpolation in Python Bokeh like matplotlib?

爱⌒轻易说出口 提交于 2020-01-25 10:55:13

问题


Is there any way to plot 2D array as an image using Bokeh with interpolation like in Matplotlib? I am able to plot using an example: https://docs.bokeh.org/en/latest/docs/gallery/image.html However, the image is to coarse. I like the way interpolation work in Matplotlib: https://matplotlib.org/gallery/images_contours_and_fields/interpolation_methods.html

I tried to perform interpolation beforehand but the matrix size now is to big.


回答1:


If you are working with a large dataset then you could try Bokeh in combination with Datashader/HoloViews like in this example. When zooming in, Datashader can dynamically create new high quality images from your data that could be displayed in your Bokeh plot.




回答2:


Not an answer but an observation - I've noticed that plotting an image via an image_url source it appears interpolated when zoomed in whilst if you read in the same image and display it from a columndatasource via 'image' it then appears blocky when zoomed. I'd love to know how to make it appear interpolated too when zoomed, eg like the raw png image appears. Holoview/datashader would be a great solution but in my case I need it to work offline/as a standalone html file.




回答3:


I had the same issue and I've found the answer in pyviz's Gitter. The solution combines Holoviews and Datashader:

import holoviews as hv 
from holoviews import opts
from holoviews.operation.datashader import regrid

img = hv.Image(data)
regrid(img, upsample=True, interpolation='bilinear')


来源:https://stackoverflow.com/questions/55545343/plot-image-with-interpolation-in-python-bokeh-like-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!