Use this notebook to obtain "expected" values for

test_geom_imshow_alpha.py

test suite.

In [1]:
import numpy as np
from lets_plot import *

LetsPlot.setup_html()
In [2]:
LetsPlot.set_theme(flavor_solarized_light())

Greyscale image

In [3]:
arr = np.array([
    [50, 150, 200],
    [200, 100, 50]
    ])
In [4]:
ggplot() + geom_imshow(arr, alpha=.5)
Normalization: 0.0002799034118652344
Clipping: 6.794929504394531e-05
image_2d: 0.00014400482177734375
png.Writer: 0.0012731552124023438
base64: 4.887580871582031e-05
Out[4]:
In [5]:
# 'norm' = False
ggplot() + geom_imshow(arr, norm=False, alpha=.5)
Normalization: 0.0002148151397705078
Clipping: 0.0002758502960205078
image_2d: 0.0001251697540283203
png.Writer: 0.00023508071899414062
base64: 4.1961669921875e-05
Out[5]:
In [6]:
# With NaN-s
arr_nan = np.array([
    [50., np.nan, 200.],
    [np.nan, 100., 50.]
    ])

ggplot() + geom_imshow(arr_nan, alpha=0.5)
LA add alpha: 5.817413330078125e-05
Normalization: 0.0004942417144775391
Clipping: 5.1975250244140625e-05
image_2d: 0.0001399517059326172
png.Writer: 0.0002028942108154297
base64: 3.409385681152344e-05
Out[6]:

Alpha + cmap

In [7]:
ggplot() + geom_imshow(arr, cmap="magma", alpha=0.5)
Normalization: 0.00017714500427246094
Clipping: 0.00016498565673828125
image_2d: 4.8160552978515625e-05
png.Writer: 0.007149696350097656
base64: 0.00011801719665527344
Out[7]:
In [8]:
# With NaN-s
arr_nan = np.array([
    [50., np.nan, 200.],
    [np.nan, 100., 50.]
    ])

ggplot() + geom_imshow(arr_nan, cmap="magma", alpha=0.5)
Normalization: 0.00024199485778808594
Clipping: 0.000186920166015625
image_2d: 5.412101745605469e-05
png.Writer: 0.007398843765258789
base64: 0.0001480579376220703
Out[8]:

Color image

In [9]:
# RGB image

A2x3x3 = np.array([
    [[255, 0, 0], [0, 255, 0], [0, 0, 255]],
    [[0, 255, 0], [0, 0, 255], [255, 0, 0]]
    ])

ggplot() + geom_imshow(A2x3x3)
Normalization: 2.288818359375e-05
Clipping: 0.00014495849609375
image_2d: 3.409385681152344e-05
png.Writer: 0.00011992454528808594
base64: 3.218650817871094e-05
Out[9]:
In [10]:
ggplot() + geom_imshow(A2x3x3, alpha=0.5)
Normalization: 9.298324584960938e-05
Clipping: 0.00023794174194335938
image_2d: 3.910064697265625e-05
png.Writer: 0.0002899169921875
base64: 3.600120544433594e-05
Out[10]:
In [11]:
# RGBA image (with alpha channel)

A2x3x4 = np.array([
    [[1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 1]],
    [[0, 1, 0, 0.3], [0, 0, 1, 0.3], [1, 0, 0, 0.3]]
    ])
In [12]:
ggplot() + geom_imshow(A2x3x4)
Normalization: 3.790855407714844e-05
Clipping: 0.00010609626770019531
image_2d: 5.4836273193359375e-05
png.Writer: 0.00015616416931152344
base64: 3.314018249511719e-05
Out[12]:
In [13]:
ggplot() + geom_imshow(A2x3x4, alpha=0.5)
Normalization: 5.984306335449219e-05
Clipping: 8.511543273925781e-05
image_2d: 9.012222290039062e-05
png.Writer: 0.0002319812774658203
base64: 4.1961669921875e-05
Out[13]:
In [14]:
_.as_dict()
Out[14]:
{'mapping': {},
 'data_meta': {},
 'theme': {'flavor': 'solarized_light'},
 'kind': 'plot',
 'scales': [],
 'layers': [{'geom': 'image',
   'mapping': {},
   'data_meta': {},
   'href': 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAYAAACddGYaAAAAHElEQVR4nGP4z8DQwPAfiBn+gzCDGpBQAwqqAQBuAwft32FBFAAAAABJRU5ErkJggg==',
   'xmin': -0.5,
   'ymin': -0.5,
   'xmax': 2.5,
   'ymax': 1.5}],
 'metainfo_list': []}
In [ ]: