{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Use this notebook to obtain \"expected\" values for \n", "```\n", "test_geom_imshow_alpha.py\n", "```\n", "test suite." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import numpy as np\n", "from lets_plot import *\n", "\n", "LetsPlot.setup_html()\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "LetsPlot.set_theme(flavor_solarized_light())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Greyscale image" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "arr = np.array([\n", " [50, 150, 200],\n", " [200, 100, 50]\n", " ])\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Normalization: 0.0002799034118652344\n", "Clipping: 6.794929504394531e-05\n", "image_2d: 0.00014400482177734375\n", "png.Writer: 0.0012731552124023438\n", "base64: 4.887580871582031e-05\n" ] }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot() + geom_imshow(arr, alpha=.5)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Normalization: 0.0002148151397705078\n", "Clipping: 0.0002758502960205078\n", "image_2d: 0.0001251697540283203\n", "png.Writer: 0.00023508071899414062\n", "base64: 4.1961669921875e-05\n" ] }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 'norm' = False\n", "ggplot() + geom_imshow(arr, norm=False, alpha=.5)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "LA add alpha: 5.817413330078125e-05\n", "Normalization: 0.0004942417144775391\n", "Clipping: 5.1975250244140625e-05\n", "image_2d: 0.0001399517059326172\n", "png.Writer: 0.0002028942108154297\n", "base64: 3.409385681152344e-05\n" ] }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# With NaN-s\n", "arr_nan = np.array([\n", " [50., np.nan, 200.],\n", " [np.nan, 100., 50.]\n", " ])\n", "\n", "ggplot() + geom_imshow(arr_nan, alpha=0.5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Alpha + cmap" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Normalization: 0.00017714500427246094\n", "Clipping: 0.00016498565673828125\n", "image_2d: 4.8160552978515625e-05\n", "png.Writer: 0.007149696350097656\n", "base64: 0.00011801719665527344\n" ] }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot() + geom_imshow(arr, cmap=\"magma\", alpha=0.5)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Normalization: 0.00024199485778808594\n", "Clipping: 0.000186920166015625\n", "image_2d: 5.412101745605469e-05\n", "png.Writer: 0.007398843765258789\n", "base64: 0.0001480579376220703\n" ] }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# With NaN-s\n", "arr_nan = np.array([\n", " [50., np.nan, 200.],\n", " [np.nan, 100., 50.]\n", " ])\n", "\n", "ggplot() + geom_imshow(arr_nan, cmap=\"magma\", alpha=0.5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Color image" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Normalization: 2.288818359375e-05\n", "Clipping: 0.00014495849609375\n", "image_2d: 3.409385681152344e-05\n", "png.Writer: 0.00011992454528808594\n", "base64: 3.218650817871094e-05\n" ] }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# RGB image\n", "\n", "A2x3x3 = np.array([\n", " [[255, 0, 0], [0, 255, 0], [0, 0, 255]],\n", " [[0, 255, 0], [0, 0, 255], [255, 0, 0]]\n", " ])\n", "\n", "ggplot() + geom_imshow(A2x3x3)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Normalization: 9.298324584960938e-05\n", "Clipping: 0.00023794174194335938\n", "image_2d: 3.910064697265625e-05\n", "png.Writer: 0.0002899169921875\n", "base64: 3.600120544433594e-05\n" ] }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot() + geom_imshow(A2x3x3, alpha=0.5)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "# RGBA image (with alpha channel)\n", "\n", "A2x3x4 = np.array([\n", " [[1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 1]],\n", " [[0, 1, 0, 0.3], [0, 0, 1, 0.3], [1, 0, 0, 0.3]]\n", " ])" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Normalization: 3.790855407714844e-05\n", "Clipping: 0.00010609626770019531\n", "image_2d: 5.4836273193359375e-05\n", "png.Writer: 0.00015616416931152344\n", "base64: 3.314018249511719e-05\n" ] }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot() + geom_imshow(A2x3x4)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Normalization: 5.984306335449219e-05\n", "Clipping: 8.511543273925781e-05\n", "image_2d: 9.012222290039062e-05\n", "png.Writer: 0.0002319812774658203\n", "base64: 4.1961669921875e-05\n" ] }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot() + geom_imshow(A2x3x4, alpha=0.5)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'mapping': {},\n", " 'data_meta': {},\n", " 'theme': {'flavor': 'solarized_light'},\n", " 'kind': 'plot',\n", " 'scales': [],\n", " 'layers': [{'geom': 'image',\n", " 'mapping': {},\n", " 'data_meta': {},\n", " 'href': 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAYAAACddGYaAAAAHElEQVR4nGP4z8DQwPAfiBn+gzCDGpBQAwqqAQBuAwft32FBFAAAAABJRU5ErkJggg==',\n", " 'xmin': -0.5,\n", " 'ymin': -0.5,\n", " 'xmax': 2.5,\n", " 'ymax': 1.5}],\n", " 'metainfo_list': []}" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "_.as_dict()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.7.13" } }, "nbformat": 4, "nbformat_minor": 4 }