Skip to content

Commit 7d91cb7

Browse files
committed
Update colorscales.md
1 parent 942d9c1 commit 7d91cb7

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

doc/python/colorscales.md

+31-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.10.9
23+
version: 3.10.11
2424
plotly:
2525
description: How to set, create and control continuous color scales and color
2626
bars in scatter, bar, map and heatmap figures.
@@ -632,6 +632,36 @@ fig = go.Figure(go.Heatmap(
632632
fig.show()
633633
```
634634

635+
### Positioning Colorbars
636+
637+
Colorbars can be positioned by specifying x and y coordinates. By default, the x and y values are "paper" coordinates, which refer to the plot area. You can also use coordinates based on the "container" by setting `xref="container"` or `yref="container"`. The following example uses a container reference for the x position.
638+
639+
See the positioning section of the [the figure data structure page](/python/figure-structure/#positioning-with-paper-container-coordinates-or-axis-domain-coordinates) for more details on "paper" vs "container" coordinates.
640+
641+
```python
642+
import plotly.graph_objects as go
643+
644+
import urllib
645+
import json
646+
647+
# Load heatmap data
648+
response = urllib.request.urlopen(
649+
"https://raw.githubusercontent.com/plotly/datasets/master/custom_heatmap_colorscale.json")
650+
dataset = json.load(response)
651+
652+
# Create and show figure
653+
fig = go.Figure(go.Heatmap(
654+
z=dataset["z"],
655+
colorbar=dict(
656+
x=0.2,
657+
xref="container",
658+
title="Surface Heat"
659+
)
660+
))
661+
662+
fig.show()
663+
```
664+
635665
### Reference
636666

637667
See https://plotly.com/python/reference/ for more information and chart attribute options!

0 commit comments

Comments
 (0)