import os
import ipywidgets as widgets

import bqplot.pyplot as plt
from bqplot import LinearScale

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

"""
Explanation: 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
End of explanation
"""


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

"""
Explanation: Using pyplot's imshow to display the image
End of explanation
"""


fig = plt.figure(title="Trees", padding_x=0, padding_y=0)
image = plt.imshow(ipyimage, "widget")
fig

"""
Explanation: Displaying the image inside a bqplot Figure
End of explanation
"""


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

"""
Explanation: Mixing with other marks
Image is a mark like any other, so they can be mixed and matched together.
End of explanation
"""


# Full screen
image.x = [-1, 2]
image.y = [-0.5, 2]

"""
Explanation: Its traits (attributes) will also respond dynamically to a change from the backend
End of explanation
"""


