-
Notifications
You must be signed in to change notification settings - Fork 1
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
cmid&zmid #179
Changes from 1 commit
c524fe9
f5e16f6
f9a5844
2b34c9a
03a6ddc
0e6629f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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. | ||
|
@@ -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 | ||
--- | ||
|
||
|
@@ -196,6 +196,41 @@ fig.add_trace(go.Heatmap( | |
fig.show() | ||
``` | ||
|
||
### Colorscale Midpoint | ||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's |
||
|
||
```python | ||
import plotly.graph_objects as go | ||
|
||
fig = go.Figure() | ||
|
||
fig.add_trace(go.Scatter( | ||
y=[1, 2, 0, 1], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's just use 1 trace here. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
"y": 0.5, | ||
"yanchor": "top", | ||
"title": {"text": "zmid=10", "side": "right"} | ||
})) | ||
|
||
fig.show() | ||
``` | ||
|
||
### Custom Contour Plot Colorscale | ||
|
||
```python | ||
|
@@ -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] | ||
|
There was a problem hiding this comment.
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