Skip to content

Instantly share code, notes, and snippets.

@astrofrog
Created July 11, 2023 20:22
Show Gist options
  • Save astrofrog/08735bc30c2f8980edeaae0fd0842352 to your computer and use it in GitHub Desktop.
Save astrofrog/08735bc30c2f8980edeaae0fd0842352 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import numpy as np\n",
"from bqplot import Figure, LinearScale, Axis, ColorScale\n",
"from bqplot_image_gl import ImageGL"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"image1 = np.array([[[255, 0, 0, 255], [0, 0, 255, 255]], [[255, 0, 0, 0], [0, 0, 255, 0]]]).astype(np.float32)\n",
"image1.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"image2 = np.array([[[0, 0, 255, 0], [255, 0, 0, 0]], [[0, 0, 255, 255], [255, 0, 0, 255]]]).astype(np.float32)\n",
"image2.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"scale_x = LinearScale(min=0, max=1)\n",
"scale_y = LinearScale(min=0, max=1)\n",
"scales = {'x': scale_x,\n",
" 'y': scale_y}\n",
"axis_x = Axis(scale=scale_x, label='x')\n",
"axis_y = Axis(scale=scale_y, label='y', orientation='vertical')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"figure = Figure(scales=scales, axes=[axis_x, axis_y])\n",
"\n",
"scales_image = {'x': figure.axes[0].scale,\n",
" 'y': figure.axes[1].scale,\n",
" 'image': ColorScale(min=0, max=1)}\n",
"\n",
"imagegl1 = ImageGL(image=image1, scales=scales_image, x=[0, 1], y=[0, 1])\n",
"imagegl2 = ImageGL(image=image2, scales=scales_image, x=[0, 1], y=[0, 1])\n",
"\n",
"figure.marks = (imagegl1,)\n",
"figure"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"figure = Figure(scales=scales, axes=[axis_x, axis_y])\n",
"\n",
"scales_image = {'x': figure.axes[0].scale,\n",
" 'y': figure.axes[1].scale,\n",
" 'image': ColorScale(min=0, max=1)}\n",
"\n",
"imagegl2 = ImageGL(image=image2, scales=scales_image, x=[0, 1], y=[0, 1])\n",
"\n",
"figure.marks = (imagegl2,)\n",
"figure"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"figure = Figure(scales=scales, axes=[axis_x, axis_y])\n",
"\n",
"scales_image = {'x': figure.axes[0].scale,\n",
" 'y': figure.axes[1].scale,\n",
" 'image': ColorScale(min=0, max=1)}\n",
"\n",
"imagegl1 = ImageGL(image=image1, scales=scales_image, x=[0, 1], y=[0, 1])\n",
"imagegl2 = ImageGL(image=image2, scales=scales_image, x=[0, 1], y=[0, 1])\n",
"\n",
"figure.marks = (imagegl1,imagegl2)\n",
"figure"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.2"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment