Skip to content

Commit f9a5844

Browse files
author
“mahdis-z”
committed
seperated examples for cmid-zmid
1 parent c524fe9 commit f9a5844

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

python/colorscales.md

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -196,37 +196,35 @@ fig.add_trace(go.Heatmap(
196196
fig.show()
197197
```
198198

199-
### Colorscale Midpoint
200-
The following example uses [cmid](https://plot.ly/python/reference/#scatter-marker-cmid) attribute to set the mid-point of the color domain by scaling [cmin](https://plot.ly/python/reference/#scatter-marker-cmin) and/or [cmax](https://plot.ly/python/reference/#scatter-marker-cmax) to be equidistant to this point. It only has impact when [marker.line.color](https://plot.ly/python/reference/#scattercarpet-marker-line-color) sets to a numerical array, and [marker.line.cauto](https://plot.ly/python/reference/#scattercarpet-marker-line-cauto) is `True`. The heatmap chart uses [zmid](https://plot.ly/python/reference/#heatmap-zmid) attribute to set the mid-point of the color domain by scaling [zmin](https://plot.ly/python/reference/#heatmap-zmin) and/or [zmax](https://plot.ly/python/reference/#heatmap-zmax) to be equidistant to this point.
199+
### Setting the Midpoint of a Diverging Colorscale
200+
The following example uses [marker.cmid](https://plot.ly/python/reference/#scatter-marker-cmid) attribute to set the mid-point of the color domain by scaling 'cmin' and/or 'cmax' to be equidistant to this point. It only has impact when [marker.color](https://plot.ly/python/reference/#scattercarpet-marker-line-color) sets to a numerical array, and 'marker.cauto' is `True`.
201201

202202
```python
203203
import plotly.graph_objects as go
204+
import plotly.express as px
204205

205206
fig = go.Figure()
206-
207207
fig.add_trace(go.Scatter(
208-
y=[1, 2, 0, 1],
208+
y=list(range(-5,15)),
209209
mode="markers",
210-
marker={
211-
"size": 25,
212-
"color": [1,4,8],
213-
"cmid": 0,
214-
"colorbar": {
215-
"len": 0.5,
216-
"y": 1,
217-
"yanchor": "top",
218-
"title": {"text": "cmid=0", "side": "right"}
219-
}}))
210+
marker={"size": 25, "color": list(range(-10,10)), "cmid": 0}))
220211

221-
fig.add_trace(go.Heatmap(
222-
z=[[1, 5, 3, 2], [5, 3, 7, 9], [3, 2, 6, 4]],
223-
zmid=10,
224-
colorbar={
225-
"len": 0.5,
226-
"y": 0.5,
227-
"yanchor": "top",
228-
"title": {"text": "zmid=10", "side": "right"}
229-
}))
212+
fig.show()
213+
```
214+
215+
The heatmap chart uses [marker.zmid](https://plot.ly/python/reference/#scatter-marker-zmid) attribute to set the mid-point of the color domain.
216+
217+
```python
218+
import plotly.graph_objects as go
219+
220+
a = list(range(-15,5))
221+
b = list(range(-10,10))
222+
c = list(range(-5,15))
223+
224+
fig = go.Figure(go.Heatmap(
225+
z=[a, b, c],
226+
colorscale='RdBu',
227+
zmid=0))
230228

231229
fig.show()
232230
```

0 commit comments

Comments
 (0)