1
1
#![ allow( dead_code) ]
2
2
3
+ use std:: vec;
3
4
use plotly:: common:: { Anchor , AxisSide , Font , Title } ;
4
5
use plotly:: layout:: {
5
6
Annotation , Axis , GridPattern , Layout , LayoutGrid , Legend , RowOrder , TraceOrder ,
@@ -40,7 +41,7 @@ fn simple_subplot_matches_x_axis() {
40
41
plot. add_trace ( trace1) ;
41
42
plot. add_trace ( trace2) ;
42
43
43
- let layout = Layout :: new ( ) . x_axis ( Axis :: new ( ) . matches ( "x2" ) ) . grid (
44
+ let layout = Layout :: new ( ) . x_axis ( Vec :: from ( [ Some ( Box :: new ( Axis :: new ( ) . matches ( "x2" ) ) ) ] ) ) . grid (
44
45
LayoutGrid :: new ( )
45
46
. rows ( 1 )
46
47
. columns ( 2 )
@@ -50,7 +51,7 @@ fn simple_subplot_matches_x_axis() {
50
51
51
52
plot. show ( ) ;
52
53
}
53
-
54
+ //
54
55
fn simple_subplot_matches_y_axis ( ) {
55
56
let trace1 = Scatter :: new ( vec ! [ 1 , 2 , 3 ] , vec ! [ 4 , 5 , 6 ] ) . name ( "trace1" ) ;
56
57
let trace2 = Scatter :: new ( vec ! [ 20 , 30 , 40 ] , vec ! [ 50 , 60 , 70 ] )
@@ -62,7 +63,7 @@ fn simple_subplot_matches_y_axis() {
62
63
plot. add_trace ( trace1) ;
63
64
plot. add_trace ( trace2) ;
64
65
65
- let layout = Layout :: new ( ) . y_axis ( Axis :: new ( ) . matches ( "y2" ) ) . grid (
66
+ let layout = Layout :: new ( ) . y_axis ( Vec :: from ( [ Some ( Box :: new ( Axis :: new ( ) . matches ( "x2" ) ) ) ] ) ) . grid (
66
67
LayoutGrid :: new ( )
67
68
. rows ( 1 )
68
69
. columns ( 2 )
@@ -72,7 +73,7 @@ fn simple_subplot_matches_y_axis() {
72
73
73
74
plot. show ( ) ;
74
75
}
75
-
76
+ //
76
77
fn custom_sized_subplot ( ) {
77
78
let trace1 = Scatter :: new ( vec ! [ 1 , 2 , 3 ] , vec ! [ 4 , 5 , 6 ] ) . name ( "trace1" ) ;
78
79
let trace2 = Scatter :: new ( vec ! [ 20 , 30 , 40 ] , vec ! [ 50 , 60 , 70 ] )
@@ -84,10 +85,14 @@ fn custom_sized_subplot() {
84
85
plot. add_trace ( trace1) ;
85
86
plot. add_trace ( trace2) ;
86
87
88
+ let mut x_axis = Vec :: new ( ) ;
89
+ x_axis. push ( Some ( Box :: new ( Axis :: new ( ) . domain ( & [ 0. , 0.7 ] ) ) ) ) ;
90
+ x_axis. push ( Some ( Box :: new ( Axis :: new ( ) . domain ( & [ 0.8 , 1. ] ) ) ) ) ;
91
+ let y_axis = Vec :: from ( [ Some ( Box :: new ( Axis :: new ( ) . anchor ( "x2" ) ) ) ] ) ;
92
+
87
93
let layout = Layout :: new ( )
88
- . x_axis ( Axis :: new ( ) . domain ( & [ 0. , 0.7 ] ) )
89
- . y_axis2 ( Axis :: new ( ) . anchor ( "x2" ) )
90
- . x_axis2 ( Axis :: new ( ) . domain ( & [ 0.8 , 1. ] ) ) ;
94
+ . x_axis ( x_axis)
95
+ . y_axis ( y_axis) ;
91
96
plot. set_layout ( layout) ;
92
97
93
98
plot. show ( ) ;
@@ -162,11 +167,13 @@ fn stacked_subplots_with_shared_x_axis() {
162
167
plot. add_trace ( trace2) ;
163
168
plot. add_trace ( trace3) ;
164
169
170
+ let mut y_axis = Vec :: new ( ) ;
171
+ y_axis. push ( Some ( Box :: new ( Axis :: new ( ) . domain ( & [ 0. , 0.33 ] ) ) ) ) ;
172
+ y_axis. push ( Some ( Box :: new ( Axis :: new ( ) . domain ( & [ 0.33 , 0.66 ] ) ) ) ) ;
173
+ y_axis. push ( Some ( Box :: new ( Axis :: new ( ) . domain ( & [ 0.66 , 1. ] ) ) ) ) ;
165
174
let layout = Layout :: new ( )
166
- . y_axis ( Axis :: new ( ) . domain ( & [ 0. , 0.33 ] ) )
167
175
. legend ( Legend :: new ( ) . trace_order ( TraceOrder :: Reversed ) )
168
- . y_axis2 ( Axis :: new ( ) . domain ( & [ 0.33 , 0.66 ] ) )
169
- . y_axis3 ( Axis :: new ( ) . domain ( & [ 0.66 , 1. ] ) ) ;
176
+ . y_axis ( y_axis) ;
170
177
plot. set_layout ( layout) ;
171
178
172
179
plot. show ( ) ;
@@ -193,22 +200,29 @@ fn multiple_custom_sized_subplots() {
193
200
plot. add_trace ( trace3) ;
194
201
plot. add_trace ( trace4) ;
195
202
203
+ let mut x_axis = Vec :: new ( ) ;
204
+ x_axis. push ( Some ( Box :: new ( Axis :: new ( ) . domain ( & [ 0. , 0.45 ] ) . anchor ( "y1" ) ) ) ) ;
205
+ x_axis. push ( Some ( Box :: new ( Axis :: new ( ) . domain ( & [ 0.55 , 1. ] ) . anchor ( "y2" ) ) ) ) ;
206
+ x_axis. push ( Some ( Box :: new ( Axis :: new ( ) . domain ( & [ 0.55 , 1. ] ) . anchor ( "y3" ) ) ) ) ;
207
+ x_axis. push ( Some ( Box :: new ( Axis :: new ( ) . domain ( & [ 0. , 1. ] ) . anchor ( "y4" ) ) ) ) ;
208
+
209
+ let mut y_axis = Vec :: new ( ) ;
210
+ y_axis. push ( Some ( Box :: new ( Axis :: new ( ) . domain ( & [ 0.5 , 1. ] ) . anchor ( "x1" ) ) ) ) ;
211
+ y_axis. push ( Some ( Box :: new ( Axis :: new ( ) . domain ( & [ 0.8 , 1. ] ) . anchor ( "x2" ) ) ) ) ;
212
+ y_axis. push ( Some ( Box :: new ( Axis :: new ( ) . domain ( & [ 0.5 , 0.75 ] ) . anchor ( "x3" ) ) ) ) ;
213
+ y_axis. push ( Some ( Box :: new ( Axis :: new ( ) . domain ( & [ 0. , 0.45 ] ) . anchor ( "x4" ) ) ) ) ;
214
+
196
215
let layout = Layout :: new ( )
197
216
. title ( "Multiple Custom Sized Subplots" )
198
- . x_axis ( Axis :: new ( ) . domain ( & [ 0. , 0.45 ] ) . anchor ( "y1" ) )
199
- . y_axis ( Axis :: new ( ) . domain ( & [ 0.5 , 1. ] ) . anchor ( "x1" ) )
200
- . x_axis2 ( Axis :: new ( ) . domain ( & [ 0.55 , 1. ] ) . anchor ( "y2" ) )
201
- . y_axis2 ( Axis :: new ( ) . domain ( & [ 0.8 , 1. ] ) . anchor ( "x2" ) )
202
- . x_axis3 ( Axis :: new ( ) . domain ( & [ 0.55 , 1. ] ) . anchor ( "y3" ) )
203
- . y_axis3 ( Axis :: new ( ) . domain ( & [ 0.5 , 0.75 ] ) . anchor ( "x3" ) )
204
- . x_axis4 ( Axis :: new ( ) . domain ( & [ 0. , 1. ] ) . anchor ( "y4" ) )
205
- . y_axis4 ( Axis :: new ( ) . domain ( & [ 0. , 0.45 ] ) . anchor ( "x4" ) ) ;
217
+ . x_axis ( x_axis)
218
+ . y_axis ( y_axis) ;
219
+
206
220
plot. set_layout ( layout) ;
207
221
208
222
plot. show ( ) ;
209
223
}
210
224
211
- // Multiple Axes
225
+ // // Multiple Axes
212
226
fn two_y_axes ( ) {
213
227
let trace1 = Scatter :: new ( vec ! [ 1 , 2 , 3 ] , vec ! [ 40 , 50 , 60 ] ) . name ( "trace1" ) ;
214
228
let trace2 = Scatter :: new ( vec ! [ 2 , 3 , 4 ] , vec ! [ 4 , 5 , 6 ] )
@@ -219,16 +233,17 @@ fn two_y_axes() {
219
233
plot. add_trace ( trace1) ;
220
234
plot. add_trace ( trace2) ;
221
235
236
+ let mut y_axis = Vec :: new ( ) ;
237
+ y_axis. push ( Some ( Box :: new ( Axis :: new ( ) . title ( "yaxis title" ) ) ) ) ;
238
+ y_axis. push ( Some ( Box :: new ( Axis :: new ( ) . title ( Title :: from ( "yaxis2 title" ) . font ( Font :: new ( ) . color ( Rgb :: new ( 148 , 103 , 189 ) ) ) )
239
+ . tick_font ( Font :: new ( ) . color ( Rgb :: new ( 148 , 103 , 189 ) ) )
240
+ . overlaying ( "y" )
241
+ . side ( AxisSide :: Right ) ) ) ) ;
242
+
222
243
let layout = Layout :: new ( )
223
244
. title ( "Double Y Axis Example" )
224
- . y_axis ( Axis :: new ( ) . title ( "yaxis title" ) )
225
- . y_axis2 (
226
- Axis :: new ( )
227
- . title ( Title :: from ( "yaxis2 title" ) . font ( Font :: new ( ) . color ( Rgb :: new ( 148 , 103 , 189 ) ) ) )
228
- . tick_font ( Font :: new ( ) . color ( Rgb :: new ( 148 , 103 , 189 ) ) )
229
- . overlaying ( "y" )
230
- . side ( AxisSide :: Right ) ,
231
- ) ;
245
+ . y_axis ( y_axis) ;
246
+
232
247
plot. set_layout ( layout) ;
233
248
234
249
plot. show ( ) ;
@@ -248,41 +263,38 @@ fn multiple_axes() {
248
263
plot. add_trace ( trace3) ;
249
264
plot. add_trace ( trace4) ;
250
265
251
- let layout = Layout :: new ( )
252
- . title ( "multiple y-axes example" )
253
- . width ( 800 )
254
- . x_axis ( Axis :: new ( ) . domain ( & [ 0.3 , 0.7 ] ) )
255
- . y_axis (
256
- Axis :: new ( )
266
+ let mut y_axis = Vec :: new ( ) ;
267
+
268
+ y_axis. push ( Some ( Box :: new ( Axis :: new ( )
257
269
. title ( Title :: from ( "yaxis title" ) . font ( Font :: new ( ) . color ( "#1f77b4" ) ) )
258
- . tick_font ( Font :: new ( ) . color ( "#1f77b4" ) ) ,
259
- )
260
- . y_axis2 (
261
- Axis :: new ( )
270
+ . tick_font ( Font :: new ( ) . color ( "#1f77b4" ) ) ) ) ) ;
271
+ y_axis. push ( Some ( Box :: new ( Axis :: new ( )
262
272
. title ( Title :: from ( "yaxis2 title" ) . font ( Font :: new ( ) . color ( "#ff7f0e" ) ) )
263
273
. tick_font ( Font :: new ( ) . color ( "#ff7f0e" ) )
264
274
. anchor ( "free" )
265
275
. overlaying ( "y" )
266
276
. side ( AxisSide :: Left )
267
- . position ( 0.15 ) ,
268
- )
269
- . y_axis3 (
270
- Axis :: new ( )
277
+ . position ( 0.15 ) ) ) ) ;
278
+ y_axis. push ( Some ( Box :: new ( Axis :: new ( )
271
279
. title ( Title :: from ( "yaxis3 title" ) . font ( Font :: new ( ) . color ( "#d62728" ) ) )
272
280
. tick_font ( Font :: new ( ) . color ( "#d62728" ) )
273
281
. anchor ( "x" )
274
282
. overlaying ( "y" )
275
- . side ( AxisSide :: Right ) ,
276
- )
277
- . y_axis4 (
278
- Axis :: new ( )
283
+ . side ( AxisSide :: Right ) ) ) ) ;
284
+ y_axis. push ( Some ( Box :: new ( Axis :: new ( )
279
285
. title ( Title :: from ( "yaxis4 title" ) . font ( Font :: new ( ) . color ( "#9467bd" ) ) )
280
286
. tick_font ( Font :: new ( ) . color ( "#9467bd" ) )
281
287
. anchor ( "free" )
282
288
. overlaying ( "y" )
283
289
. side ( AxisSide :: Right )
284
- . position ( 0.85 ) ,
285
- ) ;
290
+ . position ( 0.85 ) ) ) ) ;
291
+
292
+
293
+ let layout = Layout :: new ( )
294
+ . title ( "multiple y-axes example" )
295
+ . width ( 800 )
296
+ . x_axis ( Vec :: from ( [ Some ( Box :: new ( Axis :: new ( ) . domain ( & [ 0.3 , 0.7 ] ) ) ) ] ) )
297
+ . y_axis ( y_axis) ;
286
298
plot. set_layout ( layout) ;
287
299
288
300
plot. show ( ) ;
0 commit comments