How do I work with images in Bokeh (Python)

前端 未结 4 1465
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-01 18:39

For example you can plot an image in matplotlib using this code:

%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img=mpim         


        
4条回答
  •  时光说笑
    2020-12-01 18:57

    You can use the ImageURL glyph (image_url plot method)to load images locally or from the 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, w=0.8, h=0.6)
    ## could also leave out keywords
    # p.image_url(['tree.png'], 0, 1, 0.8, h=0.6)  
    show(p)
    

    One gotcha - if you graph only an image (and no other data), you'll have to explicitly set the plot ranges.

    Here's the docs:

    http://docs.bokeh.org/en/latest/docs/reference/models/glyphs.html#bokeh.models.glyphs.ImageURL

提交回复
热议问题