Skip to content

cmid&zmid #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 14, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions python/colorscales.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jupyter:
extension: .md
format_name: markdown
format_version: '1.1'
jupytext_version: 1.1.1
jupytext_version: 1.2.1
kernelspec:
display_name: Python 3
language: python
Expand All @@ -20,7 +20,7 @@ jupyter:
name: python
nbconvert_exporter: python
pygments_lexer: ipython3
version: 3.6.8
version: 3.7.3
plotly:
description: How to set colorscales and heatmap colorscales in Python and Plotly.
Divergent, sequential, and qualitative colorscales.
Expand All @@ -32,8 +32,8 @@ jupyter:
name: Colorscales
order: 22
permalink: python/colorscales/
thumbnail: thumbnail/heatmap_colorscale.jpg
redirect_from: python/logarithmic-color-scale/
thumbnail: thumbnail/heatmap_colorscale.jpg
v4upgrade: true
---

Expand Down Expand Up @@ -196,6 +196,41 @@ fig.add_trace(go.Heatmap(
fig.show()
```

### Colorscale Midpoint
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the midpoint of a diverging colorscale

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's marker.color and not marker.line.color?


```python
import plotly.graph_objects as go

fig = go.Figure()

fig.add_trace(go.Scatter(
y=[1, 2, 0, 1],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the data should range from, say -5 to +15

mode="markers",
marker={
"size": 25,
"color": [1,4,8],
"cmid": 0,
"colorbar": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove the colorbar settings

"len": 0.5,
"y": 1,
"yanchor": "top",
"title": {"text": "cmid=0", "side": "right"}
}}))

fig.add_trace(go.Heatmap(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's just use 1 trace here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe make a separate plot for the heatmap and say "heatmap uses zmid to do the same thing"

z=[[1, 5, 3, 2], [5, 3, 7, 9], [3, 2, 6, 4]],
zmid=10,
colorbar={
"len": 0.5,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you could use here a colormap for which the midpoint is white, like 'RdBu', so that the midpoint is more visible.

"y": 0.5,
"yanchor": "top",
"title": {"text": "zmid=10", "side": "right"}
}))

fig.show()
```

### Custom Contour Plot Colorscale

```python
Expand Down Expand Up @@ -271,7 +306,7 @@ fig = go.Figure(go.Heatmap(
[1., 'rgb(0, 0, 0)'], #100000

],
colorbar = dict(
colorbar= dict(
tick0= 0,
tickmode= 'array',
tickvals= [0, 1000, 10000, 100000]
Expand Down