The Image Mark

Image is a Mark object, used to visualize images in standard format (png, jpg etc...), in a bqplot Figure

It takes as input an ipywidgets Image widget

The ipywidgets Image


In [ ]:
import os
import ipywidgets as widgets

import bqplot.pyplot as plt
from bqplot import LinearScale

In [ ]:
image_path = os.path.abspath('../../data_files/trees.jpg')

with open(image_path, 'rb') as f:
    raw_image = f.read()
ipyimage = widgets.Image(value=raw_image, format='jpg')
ipyimage

Using pyplot's imshow to display the image


In [ ]:
plt.figure(padding_y=0)
axes_options = {'x': {'visible': False}, 'y': {'visible': False}}
plt.imshow(image_path, 'filename')
plt.show()

Displaying the image inside a bqplot Figure


In [ ]:
fig = plt.figure(title='Trees', padding_x=0, padding_y=0)
image = plt.imshow(ipyimage, 'widget')
fig

Mixing with other marks

Image is a mark like any other, so they can be mixed and matched together.


In [ ]:
fig = plt.figure(padding_x=0, padding_y=0)
plt.scales(scales={'x': LinearScale(min=-1, max=2), 
                   'y': LinearScale(min=-0.5, max=2)})
image = plt.imshow(ipyimage, format='widget')
plt.plot([0, 1, 1, 0, 0], [0, 0, 1, 1, 0], 'r')
fig

Its traits (attributes) will also respond dynamically to a change from the backend


In [ ]:
# Full screen
image.x = [-1, 2]
image.y = [-.5, 2]