You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Contrast rescaling im imshow with binary string
359
+
360
+
When the image is passed to the plotly figure as a binary string (which is the default mode for RGB images), and when the image is rescaled to adjust the contrast (for example when setting `zmin` and `zmax`), the original intensity values are not passed to the plotly figure and therefore no intensity value is displayed in the hover.
361
+
362
+
```python
363
+
import plotly.express as px
364
+
from skimage import data
365
+
import numpy as np
366
+
img = np.arange(100).reshape((10, 10))
367
+
fig = px.imshow(img, binary_string=True)
368
+
# You can check that only x and y are displayed in the hover
369
+
# You can use a hovertemplate to override the hover information
370
+
# See https://plotly.com/python/hover-text-and-formatting/#customize-tooltip-text-with-a-hovertemplate
371
+
fig.show()
372
+
```
373
+
374
+
You can set `binary_string=False` if you want the intensity value to appear in the hover even for a rescaled image. In the example below we also modify the hovertemplate to display both `z` (the data of the original image array) and `color` (the pixel value displayed in the figure).
375
+
376
+
```python
377
+
import plotly.express as px
378
+
from skimage import data
379
+
img = data.chelsea()
380
+
# Increase contrast by clipping the data range between 50 and 200
### Changing the level of compression of the binary string in `px.imshow`
359
389
360
390
The `binary_compression_level` parameter controls the level of compression to be used by the backend creating the png string. Two different backends can be used, `pypng` (which is a dependency of `plotly` and is therefore always available), and `pil` for Pillow, which is often more performant. The compression level has to be between 0 (no compression) and 9 (highest compression), although increasing the compression above 4 and 5 usually only offers diminishing returns (no significant compression gain, at the cost of a longer execution time).
0 commit comments