# See: https://ipywidgets.readthedocs.io/en/latest/examples/Using%20Interact.html
# for more details about the widgets
%matplotlib inline
from ipywidgets import interactive, fixed
import matplotlib.pyplot as plt
import numpy as np
# Now using matplotlib for visualization
def create_grayscale_pixel(value, size=255):
grayscale_img = np.ones((size, size), dtype=np.uint8) * value
plt_img = plt.imshow(grayscale_img, cmap="Greys", vmin=0, vmax=255)
# This removes the ticks and keeps the black border
plt.xticks([], [])
plt.yticks([], [])
return plt_img
interactive_plot = interactive(
create_grayscale_pixel, value=(0, 255), size=fixed(255)
)
output = interactive_plot.children[-1]
output.layout.height = '250px'
interactive_plot