Skip to content

Commit ad0dd30

Browse files
Merge pull request #2402 from plotly/legend_title_px
title.text everywhere in PX
2 parents 5b0e8d3 + ab194a4 commit ad0dd30

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

Diff for: doc/python/imshow.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.2'
9-
jupytext_version: 1.3.1
9+
jupytext_version: 1.4.2
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.6.8
23+
version: 3.7.7
2424
plotly:
2525
description: How to display image data in Python with Plotly.
2626
display_as: scientific

Diff for: packages/python/plotly/plotly/express/_core.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,9 @@ def configure_cartesian_axes(args, fig, orders):
551551
def configure_ternary_axes(args, fig, orders):
552552
fig.update_layout(
553553
ternary=dict(
554-
aaxis=dict(title=get_label(args, args["a"])),
555-
baxis=dict(title=get_label(args, args["b"])),
556-
caxis=dict(title=get_label(args, args["c"])),
554+
aaxis=dict(title_text=get_label(args, args["a"])),
555+
baxis=dict(title_text=get_label(args, args["b"])),
556+
caxis=dict(title_text=get_label(args, args["c"])),
557557
)
558558
)
559559

@@ -588,9 +588,9 @@ def configure_polar_axes(args, fig, orders):
588588
def configure_3d_axes(args, fig, orders):
589589
layout = dict(
590590
scene=dict(
591-
xaxis=dict(title=get_label(args, args["x"])),
592-
yaxis=dict(title=get_label(args, args["y"])),
593-
zaxis=dict(title=get_label(args, args["z"])),
591+
xaxis=dict(title_text=get_label(args, args["x"])),
592+
yaxis=dict(title_text=get_label(args, args["y"])),
593+
zaxis=dict(title_text=get_label(args, args["z"])),
594594
)
595595
)
596596

@@ -1611,15 +1611,19 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}):
16111611
cmid=args["color_continuous_midpoint"],
16121612
cmin=range_color[0],
16131613
cmax=range_color[1],
1614-
colorbar=dict(title=get_decorated_label(args, args[colorvar], colorvar)),
1614+
colorbar=dict(
1615+
title_text=get_decorated_label(args, args[colorvar], colorvar)
1616+
),
16151617
)
1616-
for v in ["title", "height", "width"]:
1618+
for v in ["height", "width"]:
16171619
if args[v]:
16181620
layout_patch[v] = args[v]
16191621
layout_patch["legend"] = dict(tracegroupgap=0)
16201622
if trace_name_labels:
1621-
layout_patch["legend"]["title"] = ", ".join(trace_name_labels)
1622-
if "title" not in layout_patch and args["template"].layout.margin.t is None:
1623+
layout_patch["legend"]["title_text"] = ", ".join(trace_name_labels)
1624+
if args["title"]:
1625+
layout_patch["title_text"] = args["title"]
1626+
elif args["template"].layout.margin.t is None:
16231627
layout_patch["margin"] = {"t": 60}
16241628
if (
16251629
"size" in args
@@ -1649,7 +1653,7 @@ def make_figure(args, constructor, trace_patch={}, layout_patch={}):
16491653

16501654
# Add traces, layout and frames to figure
16511655
fig.add_traces(frame_list[0]["data"] if len(frame_list) > 0 else [])
1652-
fig.layout.update(layout_patch)
1656+
fig.update_layout(layout_patch)
16531657
if "template" in args and args["template"] is not None:
16541658
fig.update_layout(template=args["template"], overwrite=True)
16551659
fig.frames = frame_list if len(frames) > 1 else []

Diff for: packages/python/plotly/plotly/express/_imshow.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def imshow(
244244
cmax=range_color[1],
245245
)
246246
if labels["color"]:
247-
layout["coloraxis1"]["colorbar"] = dict(title=labels["color"])
247+
layout["coloraxis1"]["colorbar"] = dict(title_text=labels["color"])
248248

249249
# For 2D+RGB data, use Image trace
250250
elif img.ndim == 3 and img.shape[-1] in [3, 4]:
@@ -262,10 +262,12 @@ def imshow(
262262
)
263263

264264
layout_patch = dict()
265-
for attr_name in ["title", "height", "width"]:
265+
for attr_name in ["height", "width"]:
266266
if args[attr_name]:
267267
layout_patch[attr_name] = args[attr_name]
268-
if "title" not in layout_patch and args["template"].layout.margin.t is None:
268+
if args["title"]:
269+
layout_patch["title_text"] = args["title"]
270+
elif args["template"].layout.margin.t is None:
269271
layout_patch["margin"] = {"t": 60}
270272
fig = go.Figure(data=trace, layout=layout)
271273
fig.update_layout(layout_patch)

0 commit comments

Comments
 (0)