Skip to content

Commit abf1950

Browse files
facet spacing, closes #2584
1 parent a4da999 commit abf1950

File tree

6 files changed

+79
-6
lines changed

6 files changed

+79
-6
lines changed

Diff for: CHANGELOG.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
66

77
### Added
88

9-
- `px.NO_COLOR` constant to override wide-form color assignment in Plotly Express
10-
- trendline traces are now of type `scattergl` when `render_mode="webgl"` in Plotly Express
9+
- `px.NO_COLOR` constant to override wide-form color assignment in Plotly Express ([#2614](https://github.com/plotly/plotly.py/pull/2614))
10+
- `facet_row_spacing` and `facet_col_spacing` added to Plotly Express cartesian 2d functions ([#2614](https://github.com/plotly/plotly.py/pull/2614))
11+
12+
### Fixed
13+
14+
- trendline traces are now of type `scattergl` when `render_mode="webgl"` in Plotly Express ([#2614](https://github.com/plotly/plotly.py/pull/2614))
1115

1216

1317
## [4.8.2] - 2020-06-26

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

+22
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def scatter(
2323
facet_row=None,
2424
facet_col=None,
2525
facet_col_wrap=0,
26+
facet_row_spacing=None,
27+
facet_col_spacing=None,
2628
error_x=None,
2729
error_x_minus=None,
2830
error_y=None,
@@ -74,6 +76,8 @@ def density_contour(
7476
facet_row=None,
7577
facet_col=None,
7678
facet_col_wrap=0,
79+
facet_row_spacing=None,
80+
facet_col_spacing=None,
7781
hover_name=None,
7882
hover_data=None,
7983
animation_frame=None,
@@ -141,6 +145,8 @@ def density_heatmap(
141145
facet_row=None,
142146
facet_col=None,
143147
facet_col_wrap=0,
148+
facet_row_spacing=None,
149+
facet_col_spacing=None,
144150
hover_name=None,
145151
hover_data=None,
146152
animation_frame=None,
@@ -213,6 +219,8 @@ def line(
213219
facet_row=None,
214220
facet_col=None,
215221
facet_col_wrap=0,
222+
facet_row_spacing=None,
223+
facet_col_spacing=None,
216224
error_x=None,
217225
error_x_minus=None,
218226
error_y=None,
@@ -260,6 +268,8 @@ def area(
260268
facet_row=None,
261269
facet_col=None,
262270
facet_col_wrap=0,
271+
facet_row_spacing=None,
272+
facet_col_spacing=None,
263273
animation_frame=None,
264274
animation_group=None,
265275
category_orders={},
@@ -301,6 +311,8 @@ def bar(
301311
facet_row=None,
302312
facet_col=None,
303313
facet_col_wrap=0,
314+
facet_row_spacing=None,
315+
facet_col_spacing=None,
304316
hover_name=None,
305317
hover_data=None,
306318
custom_data=None,
@@ -353,6 +365,8 @@ def histogram(
353365
facet_row=None,
354366
facet_col=None,
355367
facet_col_wrap=0,
368+
facet_row_spacing=None,
369+
facet_col_spacing=None,
356370
hover_name=None,
357371
hover_data=None,
358372
animation_frame=None,
@@ -417,6 +431,8 @@ def violin(
417431
facet_row=None,
418432
facet_col=None,
419433
facet_col_wrap=0,
434+
facet_row_spacing=None,
435+
facet_col_spacing=None,
420436
hover_name=None,
421437
hover_data=None,
422438
custom_data=None,
@@ -464,6 +480,8 @@ def box(
464480
facet_row=None,
465481
facet_col=None,
466482
facet_col_wrap=0,
483+
facet_row_spacing=None,
484+
facet_col_spacing=None,
467485
hover_name=None,
468486
hover_data=None,
469487
custom_data=None,
@@ -514,6 +532,8 @@ def strip(
514532
facet_row=None,
515533
facet_col=None,
516534
facet_col_wrap=0,
535+
facet_row_spacing=None,
536+
facet_col_spacing=None,
517537
hover_name=None,
518538
hover_data=None,
519539
custom_data=None,
@@ -1398,6 +1418,8 @@ def funnel(
13981418
facet_row=None,
13991419
facet_col=None,
14001420
facet_col_wrap=0,
1421+
facet_row_spacing=None,
1422+
facet_col_spacing=None,
14011423
hover_name=None,
14021424
hover_data=None,
14031425
custom_data=None,

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -2060,9 +2060,9 @@ def init_figure(args, subplot_type, frame_list, nrows, ncols, col_labels, row_la
20602060
row_heights = [main_size] * (nrows - 1) + [1 - main_size]
20612061
vertical_spacing = 0.01
20622062
elif args.get("facet_col_wrap", 0):
2063-
vertical_spacing = 0.07
2063+
vertical_spacing = args.get("facet_row_spacing", None) or 0.07
20642064
else:
2065-
vertical_spacing = 0.03
2065+
vertical_spacing = args.get("facet_row_spacing", None) or 0.03
20662066

20672067
if bool(args.get("marginal_y", False)):
20682068
if args["marginal_y"] == "histogram" or ("color" in args and args["color"]):
@@ -2073,7 +2073,7 @@ def init_figure(args, subplot_type, frame_list, nrows, ncols, col_labels, row_la
20732073
column_widths = [main_size] * (ncols - 1) + [1 - main_size]
20742074
horizontal_spacing = 0.005
20752075
else:
2076-
horizontal_spacing = 0.02
2076+
horizontal_spacing = args.get("facet_col_spacing", None) or 0.02
20772077
else:
20782078
# Other subplot types:
20792079
# 'scene', 'geo', 'polar', 'ternary', 'mapbox', 'domain', None

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

+5
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@
224224
"Wraps the column variable at this width, so that the column facets span multiple rows.",
225225
"Ignored if 0, and forced to 0 if `facet_row` or a `marginal` is set.",
226226
],
227+
facet_row_spacing=[
228+
"float between 0 and 1",
229+
"Spacing between facet rows, in paper units.",
230+
],
231+
facet_col_spacing=["int", "Spacing between facet columns, in paper units",],
227232
animation_frame=[
228233
colref_type,
229234
colref_desc,

Diff for: packages/python/plotly/plotly/tests/test_core/test_px/test_colors.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import plotly.express as px
2-
import numpy as np
32

43

54
def test_reversed_colorscale():
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import plotly.express as px
2+
from pytest import approx
3+
4+
5+
def test_facets():
6+
df = px.data.tips()
7+
fig = px.scatter(df, x="total_bill", y="tip")
8+
assert "xaxis2" not in fig.layout
9+
assert "yaxis2" not in fig.layout
10+
assert fig.layout.xaxis.domain == (0.0, 1.0)
11+
assert fig.layout.yaxis.domain == (0.0, 1.0)
12+
13+
fig = px.scatter(df, x="total_bill", y="tip", facet_row="sex", facet_col="smoker")
14+
assert fig.layout.xaxis4.domain[0] - fig.layout.xaxis.domain[1] == approx(0.02)
15+
assert fig.layout.yaxis4.domain[0] - fig.layout.yaxis.domain[1] == approx(0.03)
16+
17+
fig = px.scatter(df, x="total_bill", y="tip", facet_col="day", facet_col_wrap=2)
18+
assert fig.layout.xaxis4.domain[0] - fig.layout.xaxis.domain[1] == approx(0.02)
19+
assert fig.layout.yaxis4.domain[0] - fig.layout.yaxis.domain[1] == approx(0.07)
20+
21+
fig = px.scatter(
22+
df,
23+
x="total_bill",
24+
y="tip",
25+
facet_row="sex",
26+
facet_col="smoker",
27+
facet_col_spacing=0.09,
28+
facet_row_spacing=0.08,
29+
)
30+
assert fig.layout.xaxis4.domain[0] - fig.layout.xaxis.domain[1] == approx(0.09)
31+
assert fig.layout.yaxis4.domain[0] - fig.layout.yaxis.domain[1] == approx(0.08)
32+
33+
fig = px.scatter(
34+
df,
35+
x="total_bill",
36+
y="tip",
37+
facet_col="day",
38+
facet_col_wrap=2,
39+
facet_col_spacing=0.09,
40+
facet_row_spacing=0.08,
41+
)
42+
assert fig.layout.xaxis4.domain[0] - fig.layout.xaxis.domain[1] == approx(0.09)
43+
assert fig.layout.yaxis4.domain[0] - fig.layout.yaxis.domain[1] == approx(0.08)

0 commit comments

Comments
 (0)