How to load image in Bokeh App

Here is a minimal bokeh server app example:

  # main.py
  from bokeh.io import curdoc
  from bokeh.plotting import figure

  p = figure(x_range=(0,10), y_range=(0,10))
  p.image_url(x=5, y=5, w=2, h=2, url=["imgtest/static/logo.png"])

  curdoc().add_root℗

This assumes the following directory structure, as described earlier:

  imgtest/
     + main.py
     + static/
    + logo.png

Then run (in the directory above "imgtest") with

  bokeh serve --show imgtest

Thanks,

Bryan

···

On Jun 23, 2016, at 10:52, Bryan Van de ven <[email protected]> wrote:

Hi,

Image does not accept urls or image formats. It takes 2d arrays of numbers and a colormap to color the data according to. If you want to display urls of .png, etc, you want ImageURL. See, e.g.

  https://github.com/bokeh/bokeh/blob/master/examples/models/image_url.py

Thanks,

Bryan

On Jun 23, 2016, at 10:44 AM, Rakesh Partapsing <[email protected]> wrote:

I also tried the code from the example but no luck so far...

import numpy as np
from bokeh.models import ColumnDataSource, Range1d, Plot, LinearAxis, Grid
from bokeh.models.glyphs import Image
from bokeh.plotting import show
from bokeh.io import show, output_notebook

url = r"C:\foo.png"

output_notebook()

source = ColumnDataSource(dict(
   url = [url]
))

xdr = Range1d(start=0, end=1)
ydr = Range1d(start=0, end=1)

plot = Plot(
   title=None, x_range=xdr, y_range=ydr, plot_width=300, plot_height=300,
   h_symmetry=False, v_symmetry=False, min_border=0, toolbar_location=None)

image1 = Image(image=url)
plot.add_glyph(image1)

xaxis = LinearAxis()
plot.add_layout(xaxis, 'below')

yaxis = LinearAxis()
plot.add_layout(yaxis,'left')

plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

show(plot)

On Thu, Jun 23, 2016 at 5:13 PM, Raki <[email protected]> wrote:
Hi,

I wish to plot an image from url. The following code works fine inside a notebook.

from bokeh.plotting import Figure, show, output_file
from bokeh.models import ColumnDataSource

output_file('image.html')

url = r'C:\foo.png'

source = ColumnDataSource(dict(url = [url]))

p = Figure(x_range=(0,1), y_range=(0,1), plot_width=800, plot_height=400)
p.image_url(url='url', x=0, y=1, h=1, w=1, source=source)
show(p)

....but fails to run inside a bokeh app: first some errors on the x,y-ranges and also the image is not loaded + gives no error.

Any help here is much appreciated.

Best wishes,
Rakesh

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/866781e4-3d23-41a3-9a9e-9720b555bb76%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAKGpf60t%3DqKcRsF834%3DS5WNe0-VS__xdUeqb1mrUpmmqSPWRGg%40mail.gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.