Skip to content

Commit 707fb29

Browse files
committed
Update colorscales.md
1 parent 1757231 commit 707fb29

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

doc/python/colorscales.md

+38-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.14.1
9+
jupytext_version: 1.14.5
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.8.8
23+
version: 3.10.9
2424
plotly:
2525
description: How to set, create and control continuous color scales and color
2626
bars in scatter, bar, map and heatmap figures.
@@ -298,6 +298,41 @@ fig.update_layout(coloraxis_colorbar=dict(
298298
fig.show()
299299
```
300300

301+
### Using Label Aliases on Colorbars
302+
303+
*New in 5.14*
304+
305+
Using `labelalias` you can replace some labels on the `colorbar` with alternative values. In this example, the `colorbar` has five `tickvals`. Using `labelalias`, instead of displaying all labels as the numbers in `tickvals`, we swap out three of the labels for text.
306+
307+
```python
308+
import plotly.graph_objects as go
309+
310+
import urllib
311+
import json
312+
313+
# Load heatmap data
314+
response = urllib.request.urlopen(
315+
"https://raw.githubusercontent.com/plotly/datasets/master/custom_heatmap_colorscale.json")
316+
dataset = json.load(response)
317+
318+
# Create and show figure
319+
fig = go.Figure()
320+
321+
fig.add_trace(go.Heatmap(
322+
z=dataset["z"],
323+
colorbar=dict(
324+
title="Surface Heat",
325+
titleside="top",
326+
tickmode="array",
327+
tickvals=[2, 25, 50, 75, 100],
328+
labelalias={100: "Hot", 50: "Mild", 2: "Cold"},
329+
ticks="outside"
330+
)
331+
))
332+
333+
fig.show()
334+
```
335+
301336
### Custom Discretized Heatmap Color scale with Graph Objects
302337

303338
```python

0 commit comments

Comments
 (0)