@@ -19,7 +19,7 @@ subplots1()
1919function subplots2()
2020 p1 = linescatter1()
2121 p2 = linescatter2()
22- p = [p1, p2]
22+ p = [p1; p2]
2323 p
2424end
2525subplots2()
@@ -42,29 +42,127 @@ subplots3()
4242
4343``` @example subplots
4444function subplots_withcomprehension()
45- hcat([plot(scatter(x = 1:5, y = rand(5))) for i in 1:3]...)
45+ hcat([plot(scatter(x= 1:5, y= rand(5))) for i in 1:3]...)
4646end
4747subplots_withcomprehension()
4848```
4949
5050``` @example subplots
5151function subplots_withsharedaxes()
5252 data = [
53- scatter(x=1:3, y=2:4),
54- scatter(x=20:10:40, y=fill(5, 3), xaxis="x2", yaxis="y"),
55- scatter(x=2:4, y=600:100:800, xaxis="x", yaxis="y3"),
56- scatter(x=4000:1000:6000, y=7000:1000:9000, xaxis="x4", yaxis="y4")
53+ scatter(x=1:3, y=2:4),
54+ scatter(x=20:10:40, y=fill(5, 3), xaxis="x2", yaxis="y"),
55+ scatter(x=2:4, y=600:100:800, xaxis="x", yaxis="y3"),
56+ scatter(x=4000:1000:6000, y=7000:1000:9000, xaxis="x4", yaxis="y4")
5757 ]
5858 layout = Layout(
5959 xaxis_domain=[0, 0.45],
6060 yaxis_domain=[0, 0.45],
6161 xaxis4=attr(domain=[0.55, 1.0], anchor="y4"),
6262 xaxis2_domain=[0.55, 1],
6363 yaxis3_domain=[0.55, 1],
64- yaxis4=attr(domain=[0.55, 1], anchor="x4")
64+ yaxis4=attr(domain=[0.55, 1], anchor="x4")
6565 )
6666 plot(data, layout)
6767end
6868subplots_withsharedaxes()
6969```
7070
71+ ``` @example subplots
72+ function with_make_subplots1()
73+
74+ # The `shared_xaxes` argument to `make_subplots` can be used to link the x
75+ # axes of subplots in the resulting figure. The `vertical_spacing` argument
76+ # is used to control the vertical spacing between rows in the subplot grid.
77+
78+ # Here is an example that creates a figure with 3 vertically stacked
79+ # subplots with linked x axes. A small vertical spacing value is used to
80+ # reduce the spacing between subplot rows.
81+
82+ p = make_subplots(rows=3, cols=1, shared_xaxes=true, vertical_spacing=0.02)
83+ add_trace!(p, scatter(x=0:2, y=10:12), row=3, col=1)
84+ add_trace!(p, scatter(x=2:4, y=100:10:120), row=2, col=1)
85+ add_trace!(p, scatter(x=3:5, y=1000:100:1200), row=1, col=1)
86+ relayout!(p, title_text="Stacked Subplots with Shared X-Axes")
87+ p
88+ end
89+ with_make_subplots1()
90+ ```
91+
92+ ``` @example subplots
93+ function with_make_subplots2()
94+ # The `shared_yaxes` argument to `make_subplots` can be used to link the y
95+ # axes of subplots in the resulting figure.
96+
97+ # Here is an example that creates a figure with a 2 x 2 subplot grid, where
98+ # the y axes of each row are linked.
99+
100+ p = make_subplots(rows=3, cols=2, shared_yaxes=true)
101+ add_trace!(p, scatter(x=0:2, y=10:12), row=1, col=1)
102+ add_trace!(p, scatter(x=20:10:40, y=1:3), row=1, col=2)
103+ add_trace!(p, scatter(x=3:5, y=600:100:800), row=2, col=1)
104+ add_trace!(p, scatter(x=3:5, y=1000:100:1200), row=2, col=2)
105+ relayout!(p, title_text="Multiple Subplots with Shared Y-Axes")
106+ p
107+ end
108+ with_make_subplots2()
109+ ```
110+
111+ ``` @example subplots
112+ function with_make_subplots3()
113+ # The `specs` argument to `make_subplots` is used to configure per-subplot
114+ # options. `specs` must be a `Matrix` with dimensions that match those
115+ # provided as the `rows` and `cols` arguments. The elements of `specs` may
116+ # either be `missing`, indicating no subplot should be initialized starting
117+ # with this grid cell, or an instance of `Spec` containing subplot options.
118+ # The `colspan` subplot option specifies the number of grid columns that the
119+ # subplot starting in the given cell should occupy. If unspecified,
120+ # `colspan` defaults to 1.
121+
122+ # Here is an example that creates a 2 by 2 subplot grid containing 3
123+ # subplots. The subplot `specs` element for position (2, 1) has a `colspan`
124+ # value of 2, causing it to span the full figure width. The subplot `specs`
125+ # element f or position (2, 2) is `None` because no subplot begins at this
126+ # location in the grid.
127+ p = make_subplots(
128+ rows=2, cols=2,
129+ specs=[Spec() Spec(); Spec(colspan=2) missing],
130+ subplot_titles=["First Subplot" "Second Subplot"; "Third Subplot" missing]
131+ )
132+
133+ add_trace!(p, scatter(x=[1, 2], y=[1, 2]), row=1, col=1)
134+ add_trace!(p, scatter(x=[1, 2], y=[1, 2]), row=1, col=2)
135+ add_trace!(p, scatter(x=[1, 2, 3], y=[2, 1, 2]), row=2, col=1)
136+
137+ relayout!(p, showlegend=false, title_text="Specs with Subplot Title")
138+ p
139+ end
140+ with_make_subplots3()
141+ ```
142+
143+ ``` @example subplots
144+ function with_make_subplots4()
145+ # Here is an example that uses the `rowspan` and `colspan` subplot options
146+ # to create a custom subplot layout with subplots of mixed sizes.
147+ p = make_subplots(
148+ rows=5, cols=2,
149+ specs=[Spec() Spec(rowspan=2)
150+ Spec() missing
151+ Spec(rowspan=2, colspan=2) missing
152+ missing missing
153+ Spec() Spec()]
154+ )
155+
156+ add_trace!(p, scatter(x=[1, 2], y=[1, 2], name="(1,1)"), row=1, col=1)
157+ add_trace!(p, scatter(x=[1, 2], y=[1, 2], name="(1,2)"), row=1, col=2)
158+ add_trace!(p, scatter(x=[1, 2], y=[1, 2], name="(2,1)"), row=2, col=1)
159+ add_trace!(p, scatter(x=[1, 2], y=[1, 2], name="(3,1)"), row=3, col=1)
160+ add_trace!(p, scatter(x=[1, 2], y=[1, 2], name="(5,1)"), row=5, col=1)
161+ add_trace!(p, scatter(x=[1, 2], y=[1, 2], name="(5,2)"), row=5, col=2)
162+
163+ relayout!(p, height=600, width=600, title_text="specs examples")
164+ p
165+ end
166+ with_make_subplots4()
167+ ```
168+
0 commit comments