Skip to content

Commit cbe9b40

Browse files
committed
Horizontal colorbar example
1 parent 7a62e5c commit cbe9b40

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

doc/python/colorscales.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ jupyter:
55
text_representation:
66
extension: .md
77
format_name: markdown
8-
format_version: '1.2'
9-
jupytext_version: 1.6.0
8+
format_version: '1.3'
9+
jupytext_version: 1.13.4
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,10 +20,10 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.6
23+
version: 3.7.11
2424
plotly:
25-
description: How to set, create and control continuous color scales and color bars
26-
in scatter, bar, map and heatmap figures.
25+
description: How to set, create and control continuous color scales and color
26+
bars in scatter, bar, map and heatmap figures.
2727
display_as: file_settings
2828
has_thumbnail: true
2929
ipynb: ~notebook_demo/187
@@ -518,6 +518,42 @@ fig.add_trace(go.Heatmap(
518518
fig.show()
519519
```
520520

521+
### Color Bar Displayed Horizontally
522+
523+
524+
By default, color bars are displayed vertically. You can change a color bar to be displayed horizontally by setting `orientation`=`h`.
525+
526+
```python
527+
import plotly.graph_objects as go
528+
529+
import six.moves.urllib
530+
import json
531+
532+
# Load heatmap data
533+
response = six.moves.urllib.request.urlopen(
534+
"https://raw.githubusercontent.com/plotly/datasets/master/custom_heatmap_colorscale.json")
535+
dataset = json.load(response)
536+
537+
# Create and show figure
538+
fig = go.Figure()
539+
540+
fig.add_trace(go.Heatmap(
541+
z=dataset["z"],
542+
colorbar=dict(
543+
title="Surface Heat",
544+
titleside="top",
545+
tickmode="array",
546+
tickvals=[2, 50, 100],
547+
ticktext=["Cool", "Mild", "Hot"],
548+
ticks="outside",
549+
orientation='h'
550+
551+
)
552+
))
553+
554+
fig.show()
555+
```
556+
521557
### Sharing a Color Axis with Graph Objects
522558

523559
To share colorscale information in multiple subplots, you can use [coloraxis](https://plotly.com/javascript/reference/scatter/#scatter-marker-line-coloraxis).

0 commit comments

Comments
 (0)