Skip to content

Commit fe5e886

Browse files
authored
Merge pull request #179 from plotly/cmid_zmid_py_
cmid&zmid
2 parents 8e57214 + 0e6629f commit fe5e886

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

python/colorscales.md

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.1'
9-
jupytext_version: 1.1.1
9+
jupytext_version: 1.2.1
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,18 +20,21 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.6.8
23+
version: 3.7.3
2424
plotly:
2525
description: How to set colorscales and heatmap colorscales in Python and Plotly.
2626
Divergent, sequential, and qualitative colorscales.
2727
display_as: file_settings
28+
has_thumbnail: true
29+
ipynb: ~notebook_demo/187
2830
language: python
2931
layout: base
3032
name: Colorscales
3133
order: 20
3234
permalink: python/colorscales/
33-
thumbnail: thumbnail/heatmap_colorscale.jpg
3435
redirect_from: python/logarithmic-color-scale/
36+
thumbnail: thumbnail/heatmap_colorscale.jpg
37+
v4upgrade: true
3538
---
3639

3740
### Predefined colorscales in Plotly Express
@@ -193,6 +196,38 @@ fig.add_trace(go.Heatmap(
193196
fig.show()
194197
```
195198

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`.
201+
202+
```python
203+
import plotly.graph_objects as go
204+
205+
fig = go.Figure()
206+
fig.add_trace(go.Scatter(
207+
y=list(range(-5,15)),
208+
mode="markers",
209+
marker={"size": 25, "color": list(range(-3,10)), "cmid": 0}))
210+
211+
fig.show()
212+
```
213+
214+
The heatmap chart uses [marker.zmid](https://plot.ly/python/reference/#scatter-marker-zmid) attribute to set the mid-point of the color domain.
215+
216+
```python
217+
import plotly.graph_objects as go
218+
219+
a = list(range(-10,5))
220+
b = list(range(-5,10))
221+
c = list(range(-5,15))
222+
223+
fig = go.Figure(go.Heatmap(
224+
z=[a, b, c],
225+
colorscale='RdBu',
226+
zmid=0))
227+
228+
fig.show()
229+
```
230+
196231
### Custom Contour Plot Colorscale
197232

198233
```python
@@ -268,7 +303,7 @@ fig = go.Figure(go.Heatmap(
268303
[1., 'rgb(0, 0, 0)'], #100000
269304

270305
],
271-
colorbar = dict(
306+
colorbar= dict(
272307
tick0= 0,
273308
tickmode= 'array',
274309
tickvals= [0, 1000, 10000, 100000]

0 commit comments

Comments
 (0)