Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8a8cb51

Browse files
committedDec 6, 2020
improved PX defaults
1 parent 368452d commit 8a8cb51

File tree

4 files changed

+241
-209
lines changed

4 files changed

+241
-209
lines changed
 

‎CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
77
### Added
88

99
- `px.imshow` now supports `facet_col` and `animation_frame` arguments for visualizing 3-d and 4-d images [2746](https://github.com/plotly/plotly.py/pull/2746)
10+
- `px.defaults` now supports `color_discrete_map`, `symbol_map`, `line_dash_map`, `labels` and `category_orders` as well as a `.reset()` method [2957](https://github.com/plotly/plotly.py/pull/2957)
1011

1112
### Fixed
1213

‎packages/python/plotly/plotly/express/_chart_types.py

Lines changed: 100 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ def scatter(
3131
error_y_minus=None,
3232
animation_frame=None,
3333
animation_group=None,
34-
category_orders={},
35-
labels={},
34+
category_orders=None,
35+
labels=None,
3636
orientation=None,
3737
color_discrete_sequence=None,
38-
color_discrete_map={},
38+
color_discrete_map=None,
3939
color_continuous_scale=None,
4040
range_color=None,
4141
color_continuous_midpoint=None,
4242
symbol_sequence=None,
43-
symbol_map={},
43+
symbol_map=None,
4444
opacity=None,
4545
size_max=None,
4646
marginal_x=None,
@@ -82,11 +82,11 @@ def density_contour(
8282
hover_data=None,
8383
animation_frame=None,
8484
animation_group=None,
85-
category_orders={},
86-
labels={},
85+
category_orders=None,
86+
labels=None,
8787
orientation=None,
8888
color_discrete_sequence=None,
89-
color_discrete_map={},
89+
color_discrete_map=None,
9090
marginal_x=None,
9191
marginal_y=None,
9292
trendline=None,
@@ -151,8 +151,8 @@ def density_heatmap(
151151
hover_data=None,
152152
animation_frame=None,
153153
animation_group=None,
154-
category_orders={},
155-
labels={},
154+
category_orders=None,
155+
labels=None,
156156
orientation=None,
157157
color_continuous_scale=None,
158158
range_color=None,
@@ -227,13 +227,13 @@ def line(
227227
error_y_minus=None,
228228
animation_frame=None,
229229
animation_group=None,
230-
category_orders={},
231-
labels={},
230+
category_orders=None,
231+
labels=None,
232232
orientation=None,
233233
color_discrete_sequence=None,
234-
color_discrete_map={},
234+
color_discrete_map=None,
235235
line_dash_sequence=None,
236-
line_dash_map={},
236+
line_dash_map=None,
237237
log_x=False,
238238
log_y=False,
239239
range_x=None,
@@ -272,10 +272,10 @@ def area(
272272
facet_col_spacing=None,
273273
animation_frame=None,
274274
animation_group=None,
275-
category_orders={},
276-
labels={},
275+
category_orders=None,
276+
labels=None,
277277
color_discrete_sequence=None,
278-
color_discrete_map={},
278+
color_discrete_map=None,
279279
orientation=None,
280280
groupnorm=None,
281281
log_x=False,
@@ -324,10 +324,10 @@ def bar(
324324
error_y_minus=None,
325325
animation_frame=None,
326326
animation_group=None,
327-
category_orders={},
328-
labels={},
327+
category_orders=None,
328+
labels=None,
329329
color_discrete_sequence=None,
330-
color_discrete_map={},
330+
color_discrete_map=None,
331331
color_continuous_scale=None,
332332
range_color=None,
333333
color_continuous_midpoint=None,
@@ -375,10 +375,10 @@ def timeline(
375375
text=None,
376376
animation_frame=None,
377377
animation_group=None,
378-
category_orders={},
379-
labels={},
378+
category_orders=None,
379+
labels=None,
380380
color_discrete_sequence=None,
381-
color_discrete_map={},
381+
color_discrete_map=None,
382382
color_continuous_scale=None,
383383
range_color=None,
384384
color_continuous_midpoint=None,
@@ -419,10 +419,10 @@ def histogram(
419419
hover_data=None,
420420
animation_frame=None,
421421
animation_group=None,
422-
category_orders={},
423-
labels={},
422+
category_orders=None,
423+
labels=None,
424424
color_discrete_sequence=None,
425-
color_discrete_map={},
425+
color_discrete_map=None,
426426
marginal=None,
427427
opacity=None,
428428
orientation=None,
@@ -486,10 +486,10 @@ def violin(
486486
custom_data=None,
487487
animation_frame=None,
488488
animation_group=None,
489-
category_orders={},
490-
labels={},
489+
category_orders=None,
490+
labels=None,
491491
color_discrete_sequence=None,
492-
color_discrete_map={},
492+
color_discrete_map=None,
493493
orientation=None,
494494
violinmode=None,
495495
log_x=False,
@@ -535,10 +535,10 @@ def box(
535535
custom_data=None,
536536
animation_frame=None,
537537
animation_group=None,
538-
category_orders={},
539-
labels={},
538+
category_orders=None,
539+
labels=None,
540540
color_discrete_sequence=None,
541-
color_discrete_map={},
541+
color_discrete_map=None,
542542
orientation=None,
543543
boxmode=None,
544544
log_x=False,
@@ -587,10 +587,10 @@ def strip(
587587
custom_data=None,
588588
animation_frame=None,
589589
animation_group=None,
590-
category_orders={},
591-
labels={},
590+
category_orders=None,
591+
labels=None,
592592
color_discrete_sequence=None,
593-
color_discrete_map={},
593+
color_discrete_map=None,
594594
orientation=None,
595595
stripmode=None,
596596
log_x=False,
@@ -645,16 +645,16 @@ def scatter_3d(
645645
error_z_minus=None,
646646
animation_frame=None,
647647
animation_group=None,
648-
category_orders={},
649-
labels={},
648+
category_orders=None,
649+
labels=None,
650650
size_max=None,
651651
color_discrete_sequence=None,
652-
color_discrete_map={},
652+
color_discrete_map=None,
653653
color_continuous_scale=None,
654654
range_color=None,
655655
color_continuous_midpoint=None,
656656
symbol_sequence=None,
657-
symbol_map={},
657+
symbol_map=None,
658658
opacity=None,
659659
log_x=False,
660660
log_y=False,
@@ -697,12 +697,12 @@ def line_3d(
697697
error_z_minus=None,
698698
animation_frame=None,
699699
animation_group=None,
700-
category_orders={},
701-
labels={},
700+
category_orders=None,
701+
labels=None,
702702
color_discrete_sequence=None,
703-
color_discrete_map={},
703+
color_discrete_map=None,
704704
line_dash_sequence=None,
705-
line_dash_map={},
705+
line_dash_map=None,
706706
log_x=False,
707707
log_y=False,
708708
log_z=False,
@@ -738,15 +738,15 @@ def scatter_ternary(
738738
custom_data=None,
739739
animation_frame=None,
740740
animation_group=None,
741-
category_orders={},
742-
labels={},
741+
category_orders=None,
742+
labels=None,
743743
color_discrete_sequence=None,
744-
color_discrete_map={},
744+
color_discrete_map=None,
745745
color_continuous_scale=None,
746746
range_color=None,
747747
color_continuous_midpoint=None,
748748
symbol_sequence=None,
749-
symbol_map={},
749+
symbol_map=None,
750750
opacity=None,
751751
size_max=None,
752752
title=None,
@@ -778,12 +778,12 @@ def line_ternary(
778778
text=None,
779779
animation_frame=None,
780780
animation_group=None,
781-
category_orders={},
782-
labels={},
781+
category_orders=None,
782+
labels=None,
783783
color_discrete_sequence=None,
784-
color_discrete_map={},
784+
color_discrete_map=None,
785785
line_dash_sequence=None,
786-
line_dash_map={},
786+
line_dash_map=None,
787787
line_shape=None,
788788
title=None,
789789
template=None,
@@ -813,15 +813,15 @@ def scatter_polar(
813813
text=None,
814814
animation_frame=None,
815815
animation_group=None,
816-
category_orders={},
817-
labels={},
816+
category_orders=None,
817+
labels=None,
818818
color_discrete_sequence=None,
819-
color_discrete_map={},
819+
color_discrete_map=None,
820820
color_continuous_scale=None,
821821
range_color=None,
822822
color_continuous_midpoint=None,
823823
symbol_sequence=None,
824-
symbol_map={},
824+
symbol_map=None,
825825
opacity=None,
826826
direction="clockwise",
827827
start_angle=90,
@@ -858,12 +858,12 @@ def line_polar(
858858
text=None,
859859
animation_frame=None,
860860
animation_group=None,
861-
category_orders={},
862-
labels={},
861+
category_orders=None,
862+
labels=None,
863863
color_discrete_sequence=None,
864-
color_discrete_map={},
864+
color_discrete_map=None,
865865
line_dash_sequence=None,
866-
line_dash_map={},
866+
line_dash_map=None,
867867
direction="clockwise",
868868
start_angle=90,
869869
line_close=False,
@@ -898,10 +898,10 @@ def bar_polar(
898898
base=None,
899899
animation_frame=None,
900900
animation_group=None,
901-
category_orders={},
902-
labels={},
901+
category_orders=None,
902+
labels=None,
903903
color_discrete_sequence=None,
904-
color_discrete_map={},
904+
color_discrete_map=None,
905905
color_continuous_scale=None,
906906
range_color=None,
907907
color_continuous_midpoint=None,
@@ -950,10 +950,10 @@ def choropleth(
950950
custom_data=None,
951951
animation_frame=None,
952952
animation_group=None,
953-
category_orders={},
954-
labels={},
953+
category_orders=None,
954+
labels=None,
955955
color_discrete_sequence=None,
956-
color_discrete_map={},
956+
color_discrete_map=None,
957957
color_continuous_scale=None,
958958
range_color=None,
959959
color_continuous_midpoint=None,
@@ -1003,15 +1003,15 @@ def scatter_geo(
10031003
size=None,
10041004
animation_frame=None,
10051005
animation_group=None,
1006-
category_orders={},
1007-
labels={},
1006+
category_orders=None,
1007+
labels=None,
10081008
color_discrete_sequence=None,
1009-
color_discrete_map={},
1009+
color_discrete_map=None,
10101010
color_continuous_scale=None,
10111011
range_color=None,
10121012
color_continuous_midpoint=None,
10131013
symbol_sequence=None,
1014-
symbol_map={},
1014+
symbol_map=None,
10151015
opacity=None,
10161016
size_max=None,
10171017
projection=None,
@@ -1060,12 +1060,12 @@ def line_geo(
10601060
line_group=None,
10611061
animation_frame=None,
10621062
animation_group=None,
1063-
category_orders={},
1064-
labels={},
1063+
category_orders=None,
1064+
labels=None,
10651065
color_discrete_sequence=None,
1066-
color_discrete_map={},
1066+
color_discrete_map=None,
10671067
line_dash_sequence=None,
1068-
line_dash_map={},
1068+
line_dash_map=None,
10691069
projection=None,
10701070
scope=None,
10711071
center=None,
@@ -1102,10 +1102,10 @@ def scatter_mapbox(
11021102
size=None,
11031103
animation_frame=None,
11041104
animation_group=None,
1105-
category_orders={},
1106-
labels={},
1105+
category_orders=None,
1106+
labels=None,
11071107
color_discrete_sequence=None,
1108-
color_discrete_map={},
1108+
color_discrete_map=None,
11091109
color_continuous_scale=None,
11101110
range_color=None,
11111111
color_continuous_midpoint=None,
@@ -1140,10 +1140,10 @@ def choropleth_mapbox(
11401140
custom_data=None,
11411141
animation_frame=None,
11421142
animation_group=None,
1143-
category_orders={},
1144-
labels={},
1143+
category_orders=None,
1144+
labels=None,
11451145
color_discrete_sequence=None,
1146-
color_discrete_map={},
1146+
color_discrete_map=None,
11471147
color_continuous_scale=None,
11481148
range_color=None,
11491149
color_continuous_midpoint=None,
@@ -1176,8 +1176,8 @@ def density_mapbox(
11761176
custom_data=None,
11771177
animation_frame=None,
11781178
animation_group=None,
1179-
category_orders={},
1180-
labels={},
1179+
category_orders=None,
1180+
labels=None,
11811181
color_continuous_scale=None,
11821182
range_color=None,
11831183
color_continuous_midpoint=None,
@@ -1215,10 +1215,10 @@ def line_mapbox(
12151215
line_group=None,
12161216
animation_frame=None,
12171217
animation_group=None,
1218-
category_orders={},
1219-
labels={},
1218+
category_orders=None,
1219+
labels=None,
12201220
color_discrete_sequence=None,
1221-
color_discrete_map={},
1221+
color_discrete_map=None,
12221222
zoom=8,
12231223
center=None,
12241224
mapbox_style=None,
@@ -1246,15 +1246,15 @@ def scatter_matrix(
12461246
hover_name=None,
12471247
hover_data=None,
12481248
custom_data=None,
1249-
category_orders={},
1250-
labels={},
1249+
category_orders=None,
1250+
labels=None,
12511251
color_discrete_sequence=None,
1252-
color_discrete_map={},
1252+
color_discrete_map=None,
12531253
color_continuous_scale=None,
12541254
range_color=None,
12551255
color_continuous_midpoint=None,
12561256
symbol_sequence=None,
1257-
symbol_map={},
1257+
symbol_map=None,
12581258
opacity=None,
12591259
size_max=None,
12601260
title=None,
@@ -1280,7 +1280,7 @@ def parallel_coordinates(
12801280
data_frame=None,
12811281
dimensions=None,
12821282
color=None,
1283-
labels={},
1283+
labels=None,
12841284
color_continuous_scale=None,
12851285
range_color=None,
12861286
color_continuous_midpoint=None,
@@ -1304,7 +1304,7 @@ def parallel_categories(
13041304
data_frame=None,
13051305
dimensions=None,
13061306
color=None,
1307-
labels={},
1307+
labels=None,
13081308
color_continuous_scale=None,
13091309
range_color=None,
13101310
color_continuous_midpoint=None,
@@ -1332,11 +1332,11 @@ def pie(
13321332
values=None,
13331333
color=None,
13341334
color_discrete_sequence=None,
1335-
color_discrete_map={},
1335+
color_discrete_map=None,
13361336
hover_name=None,
13371337
hover_data=None,
13381338
custom_data=None,
1339-
labels={},
1339+
labels=None,
13401340
title=None,
13411341
template=None,
13421342
width=None,
@@ -1384,11 +1384,11 @@ def sunburst(
13841384
range_color=None,
13851385
color_continuous_midpoint=None,
13861386
color_discrete_sequence=None,
1387-
color_discrete_map={},
1387+
color_discrete_map=None,
13881388
hover_name=None,
13891389
hover_data=None,
13901390
custom_data=None,
1391-
labels={},
1391+
labels=None,
13921392
title=None,
13931393
template=None,
13941394
width=None,
@@ -1434,11 +1434,11 @@ def treemap(
14341434
range_color=None,
14351435
color_continuous_midpoint=None,
14361436
color_discrete_sequence=None,
1437-
color_discrete_map={},
1437+
color_discrete_map=None,
14381438
hover_name=None,
14391439
hover_data=None,
14401440
custom_data=None,
1441-
labels={},
1441+
labels=None,
14421442
title=None,
14431443
template=None,
14441444
width=None,
@@ -1488,10 +1488,10 @@ def funnel(
14881488
text=None,
14891489
animation_frame=None,
14901490
animation_group=None,
1491-
category_orders={},
1492-
labels={},
1491+
category_orders=None,
1492+
labels=None,
14931493
color_discrete_sequence=None,
1494-
color_discrete_map={},
1494+
color_discrete_map=None,
14951495
opacity=None,
14961496
orientation=None,
14971497
log_x=False,
@@ -1519,11 +1519,11 @@ def funnel_area(
15191519
values=None,
15201520
color=None,
15211521
color_discrete_sequence=None,
1522-
color_discrete_map={},
1522+
color_discrete_map=None,
15231523
hover_name=None,
15241524
hover_data=None,
15251525
custom_data=None,
1526-
labels={},
1526+
labels=None,
15271527
title=None,
15281528
template=None,
15291529
width=None,

‎packages/python/plotly/plotly/express/_core.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,34 @@ class PxDefaults(object):
4545
"width",
4646
"height",
4747
"color_discrete_sequence",
48+
"color_discrete_map",
4849
"color_continuous_scale",
4950
"symbol_sequence",
51+
"symbol_map",
5052
"line_dash_sequence",
53+
"line_dash_map",
5154
"size_max",
55+
"category_orders",
56+
"labels",
5257
]
5358

5459
def __init__(self):
60+
self.reset()
61+
62+
def reset(self):
5563
self.template = None
5664
self.width = None
5765
self.height = None
5866
self.color_discrete_sequence = None
67+
self.color_discrete_map = {}
5968
self.color_continuous_scale = None
6069
self.symbol_sequence = None
70+
self.symbol_map = {}
6171
self.line_dash_sequence = None
72+
self.line_dash_map = {}
6273
self.size_max = 20
74+
self.category_orders = {}
75+
self.labels = {}
6376

6477

6578
defaults = PxDefaults()
@@ -848,11 +861,7 @@ def one_group(x):
848861
def apply_default_cascade(args):
849862
# first we apply px.defaults to unspecified args
850863

851-
for param in (
852-
["color_discrete_sequence", "color_continuous_scale"]
853-
+ ["symbol_sequence", "line_dash_sequence", "template"]
854-
+ ["width", "height", "size_max"]
855-
):
864+
for param in defaults.__slots__:
856865
if param in args and args[param] is None:
857866
args[param] = getattr(defaults, param)
858867

‎packages/python/plotly/plotly/tests/test_core/test_px/test_px.py

Lines changed: 126 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -80,110 +80,132 @@ def test_labels():
8080

8181

8282
def test_px_templates():
83-
import plotly.io as pio
84-
import plotly.graph_objects as go
85-
86-
tips = px.data.tips()
87-
88-
# use the normal defaults
89-
fig = px.scatter()
90-
assert fig.layout.template == pio.templates[pio.templates.default]
91-
92-
# respect changes to defaults
93-
pio.templates.default = "seaborn"
94-
fig = px.scatter()
95-
assert fig.layout.template == pio.templates["seaborn"]
96-
97-
# special px-level defaults over pio defaults
98-
pio.templates.default = "seaborn"
99-
px.defaults.template = "ggplot2"
100-
fig = px.scatter()
101-
assert fig.layout.template == pio.templates["ggplot2"]
102-
103-
# accept names in args over pio and px defaults
104-
fig = px.scatter(template="seaborn")
105-
assert fig.layout.template == pio.templates["seaborn"]
106-
107-
# accept objects in args
108-
fig = px.scatter(template={})
109-
assert fig.layout.template == go.layout.Template(data_scatter=[{}])
110-
111-
# read colorway from the template
112-
fig = px.scatter(
113-
tips,
114-
x="total_bill",
115-
y="tip",
116-
color="sex",
117-
template=dict(layout_colorway=["red", "blue"]),
118-
)
119-
assert fig.data[0].marker.color == "red"
120-
assert fig.data[1].marker.color == "blue"
121-
122-
# default colorway fallback
123-
fig = px.scatter(tips, x="total_bill", y="tip", color="sex", template=dict())
124-
assert fig.data[0].marker.color == px.colors.qualitative.D3[0]
125-
assert fig.data[1].marker.color == px.colors.qualitative.D3[1]
126-
127-
# pio default template colorway fallback
128-
pio.templates.default = "seaborn"
129-
px.defaults.template = None
130-
fig = px.scatter(tips, x="total_bill", y="tip", color="sex")
131-
assert fig.data[0].marker.color == pio.templates["seaborn"].layout.colorway[0]
132-
assert fig.data[1].marker.color == pio.templates["seaborn"].layout.colorway[1]
133-
134-
# pio default template colorway fallback
135-
pio.templates.default = "seaborn"
136-
px.defaults.template = "ggplot2"
137-
fig = px.scatter(tips, x="total_bill", y="tip", color="sex")
138-
assert fig.data[0].marker.color == pio.templates["ggplot2"].layout.colorway[0]
139-
assert fig.data[1].marker.color == pio.templates["ggplot2"].layout.colorway[1]
140-
141-
# don't overwrite top margin when set in template
142-
fig = px.scatter(title="yo")
143-
assert fig.layout.margin.t is None
144-
145-
fig = px.scatter()
146-
assert fig.layout.margin.t == 60
147-
148-
fig = px.scatter(template=dict(layout_margin_t=2))
149-
assert fig.layout.margin.t is None
150-
151-
# don't force histogram gridlines when set in template
152-
pio.templates.default = "none"
153-
px.defaults.template = None
154-
fig = px.scatter(
155-
tips, x="total_bill", y="tip", marginal_x="histogram", marginal_y="histogram"
156-
)
157-
assert fig.layout.xaxis2.showgrid
158-
assert fig.layout.xaxis3.showgrid
159-
assert fig.layout.yaxis2.showgrid
160-
assert fig.layout.yaxis3.showgrid
161-
162-
fig = px.scatter(
163-
tips,
164-
x="total_bill",
165-
y="tip",
166-
marginal_x="histogram",
167-
marginal_y="histogram",
168-
template=dict(layout_yaxis_showgrid=False),
169-
)
170-
assert fig.layout.xaxis2.showgrid
171-
assert fig.layout.xaxis3.showgrid
172-
assert fig.layout.yaxis2.showgrid is None
173-
assert fig.layout.yaxis3.showgrid is None
174-
175-
fig = px.scatter(
176-
tips,
177-
x="total_bill",
178-
y="tip",
179-
marginal_x="histogram",
180-
marginal_y="histogram",
181-
template=dict(layout_xaxis_showgrid=False),
182-
)
183-
assert fig.layout.xaxis2.showgrid is None
184-
assert fig.layout.xaxis3.showgrid is None
185-
assert fig.layout.yaxis2.showgrid
186-
assert fig.layout.yaxis3.showgrid
83+
try:
84+
import plotly.io as pio
85+
import plotly.graph_objects as go
86+
87+
tips = px.data.tips()
88+
89+
# use the normal defaults
90+
fig = px.scatter()
91+
assert fig.layout.template == pio.templates[pio.templates.default]
92+
93+
# respect changes to defaults
94+
pio.templates.default = "seaborn"
95+
fig = px.scatter()
96+
assert fig.layout.template == pio.templates["seaborn"]
97+
98+
# special px-level defaults over pio defaults
99+
pio.templates.default = "seaborn"
100+
px.defaults.template = "ggplot2"
101+
fig = px.scatter()
102+
assert fig.layout.template == pio.templates["ggplot2"]
103+
104+
# accept names in args over pio and px defaults
105+
fig = px.scatter(template="seaborn")
106+
assert fig.layout.template == pio.templates["seaborn"]
107+
108+
# accept objects in args
109+
fig = px.scatter(template={})
110+
assert fig.layout.template == go.layout.Template(data_scatter=[{}])
111+
112+
# read colorway from the template
113+
fig = px.scatter(
114+
tips,
115+
x="total_bill",
116+
y="tip",
117+
color="sex",
118+
template=dict(layout_colorway=["red", "blue"]),
119+
)
120+
assert fig.data[0].marker.color == "red"
121+
assert fig.data[1].marker.color == "blue"
122+
123+
# default colorway fallback
124+
fig = px.scatter(tips, x="total_bill", y="tip", color="sex", template=dict())
125+
assert fig.data[0].marker.color == px.colors.qualitative.D3[0]
126+
assert fig.data[1].marker.color == px.colors.qualitative.D3[1]
127+
128+
# pio default template colorway fallback
129+
pio.templates.default = "seaborn"
130+
px.defaults.template = None
131+
fig = px.scatter(tips, x="total_bill", y="tip", color="sex")
132+
assert fig.data[0].marker.color == pio.templates["seaborn"].layout.colorway[0]
133+
assert fig.data[1].marker.color == pio.templates["seaborn"].layout.colorway[1]
134+
135+
# pio default template colorway fallback
136+
pio.templates.default = "seaborn"
137+
px.defaults.template = "ggplot2"
138+
fig = px.scatter(tips, x="total_bill", y="tip", color="sex")
139+
assert fig.data[0].marker.color == pio.templates["ggplot2"].layout.colorway[0]
140+
assert fig.data[1].marker.color == pio.templates["ggplot2"].layout.colorway[1]
141+
142+
# don't overwrite top margin when set in template
143+
fig = px.scatter(title="yo")
144+
assert fig.layout.margin.t is None
145+
146+
fig = px.scatter()
147+
assert fig.layout.margin.t == 60
148+
149+
fig = px.scatter(template=dict(layout_margin_t=2))
150+
assert fig.layout.margin.t is None
151+
152+
# don't force histogram gridlines when set in template
153+
pio.templates.default = "none"
154+
px.defaults.template = None
155+
fig = px.scatter(
156+
tips,
157+
x="total_bill",
158+
y="tip",
159+
marginal_x="histogram",
160+
marginal_y="histogram",
161+
)
162+
assert fig.layout.xaxis2.showgrid
163+
assert fig.layout.xaxis3.showgrid
164+
assert fig.layout.yaxis2.showgrid
165+
assert fig.layout.yaxis3.showgrid
166+
167+
fig = px.scatter(
168+
tips,
169+
x="total_bill",
170+
y="tip",
171+
marginal_x="histogram",
172+
marginal_y="histogram",
173+
template=dict(layout_yaxis_showgrid=False),
174+
)
175+
assert fig.layout.xaxis2.showgrid
176+
assert fig.layout.xaxis3.showgrid
177+
assert fig.layout.yaxis2.showgrid is None
178+
assert fig.layout.yaxis3.showgrid is None
179+
180+
fig = px.scatter(
181+
tips,
182+
x="total_bill",
183+
y="tip",
184+
marginal_x="histogram",
185+
marginal_y="histogram",
186+
template=dict(layout_xaxis_showgrid=False),
187+
)
188+
assert fig.layout.xaxis2.showgrid is None
189+
assert fig.layout.xaxis3.showgrid is None
190+
assert fig.layout.yaxis2.showgrid
191+
assert fig.layout.yaxis3.showgrid
192+
finally:
193+
# reset defaults to prevent all other tests from failing if this one does
194+
px.defaults.reset()
195+
196+
197+
def test_px_defaults():
198+
px.defaults.labels = dict(x="hey x")
199+
px.defaults.category_orders = dict(color=["b", "a"])
200+
px.defaults.color_discrete_map = dict(b="red")
201+
fig = px.scatter(x=[1, 2], y=[1, 2], color=["a", "b"])
202+
try:
203+
assert fig.data[0].name == "b"
204+
assert fig.data[0].marker.color == "red"
205+
assert fig.layout.xaxis.title.text == "hey x"
206+
finally:
207+
# reset defaults to prevent all other tests from failing if this one does
208+
px.defaults.reset()
187209

188210

189211
def assert_orderings(days_order, days_check, times_order, times_check):

0 commit comments

Comments
 (0)
Please sign in to comment.