diff --git a/doc/python/colorscales.md b/doc/python/colorscales.md
index aadef07600..fd9780b595 100644
--- a/doc/python/colorscales.md
+++ b/doc/python/colorscales.md
@@ -610,29 +610,32 @@ fig.show()
### Logarithmic Color scale with Graph Objects
+To give each factor of ten equal space on a heatmap colorbar, use the base-10 logarithm of each positive value as its color value. Set the colorbar ticks at the log-transformed positions and label them with the original values. This example leaves non-positive values blank and uses `customdata` to show original values on hover.
+
```python
+import numpy as np
import plotly.graph_objects as go
-fig = go.Figure(go.Heatmap(
- z= [[10, 100.625, 1200.5, 150.625, 2000],
- [5000.625, 60.25, 8.125, 100000, 150.625],
- [2000.5, 300.125, 50., 8.125, 12.5],
- [10.625, 1.25, 3.125, 6000.25, 100.625],
- [0, 0.625, 2.5, 50000.625, 10]],
- colorscale= [
- [0, 'rgb(250, 250, 250)'], #0
- [1./10000, 'rgb(200, 200, 200)'], #10
- [1./1000, 'rgb(150, 150, 150)'], #100
- [1./100, 'rgb(100, 100, 100)'], #1000
- [1./10, 'rgb(50, 50, 50)'], #10000
- [1., 'rgb(0, 0, 0)'], #100000
+z = np.array([
+ [10, 100.625, 1200.5, 150.625, 2000],
+ [5000.625, 60.25, 8.125, 100000, 150.625],
+ [2000.5, 300.125, 50., 8.125, 12.5],
+ [10.625, 1.25, 3.125, 6000.25, 100.625],
+ [0, 0.625, 2.5, 50000.625, 10],
+])
+ticks = [1, 10, 100, 1000, 10000, 100000]
- ],
- colorbar= dict(
- tick0= 0,
- tickmode= 'array',
- tickvals= [0, 1000, 10000, 100000]
- )
+fig = go.Figure(go.Heatmap(
+ z=np.log10(np.where(z > 0, z, np.nan)),
+ customdata=z,
+ hovertemplate="x: %{x}
y: %{y}
Value: %{customdata}",
+ hoverongaps=False,
+ colorscale=[[0, "rgb(250, 250, 250)"], [1, "rgb(0, 0, 0)"]],
+ colorbar=dict(
+ tickmode="array",
+ tickvals=np.log10(ticks),
+ ticktext=[f"{value:,}" for value in ticks],
+ ),
))
fig.show()