@@ -386,6 +386,60 @@ fn many_subplots_with_titles(show: bool, file_name: &str) {
386
386
}
387
387
// ANCHOR_END: many_subplots_with_titles
388
388
389
+ // ANCHOR: subplots_with_multiple_traces
390
+ fn subplots_with_multiple_traces ( show : bool , file_name : & str ) {
391
+ // Create multiple traces for the first subplot (left side)
392
+ let trace1 = Scatter :: new ( vec ! [ 1 , 2 , 3 , 4 ] , vec ! [ 10 , 11 , 12 , 13 ] )
393
+ . name ( "Line 1" )
394
+ . mode ( plotly:: common:: Mode :: LinesMarkers ) ;
395
+
396
+ let trace2 = Scatter :: new ( vec ! [ 1 , 2 , 3 , 4 ] , vec ! [ 8 , 9 , 10 , 11 ] )
397
+ . name ( "Line 2" )
398
+ . mode ( plotly:: common:: Mode :: LinesMarkers ) ;
399
+
400
+ let trace3 = Scatter :: new ( vec ! [ 1 , 2 , 3 , 4 ] , vec ! [ 12 , 13 , 14 , 15 ] )
401
+ . name ( "Line 3" )
402
+ . mode ( plotly:: common:: Mode :: LinesMarkers ) ;
403
+
404
+ // Create traces for the second subplot (right side)
405
+ let trace4 = Scatter :: new ( vec ! [ 1 , 2 , 3 , 4 ] , vec ! [ 20 , 25 , 30 , 35 ] )
406
+ . name ( "Dots 1" )
407
+ . x_axis ( "x2" )
408
+ . y_axis ( "y2" )
409
+ . mode ( plotly:: common:: Mode :: Markers ) ;
410
+
411
+ let trace5 = Scatter :: new ( vec ! [ 1 , 2 , 3 , 4 ] , vec ! [ 15 , 20 , 25 , 30 ] )
412
+ . name ( "Dots 2" )
413
+ . x_axis ( "x2" )
414
+ . y_axis ( "y2" )
415
+ . mode ( plotly:: common:: Mode :: Markers ) ;
416
+
417
+ let mut plot = Plot :: new ( ) ;
418
+ // Add traces to first subplot (default axes)
419
+ plot. add_trace ( trace1) ;
420
+ plot. add_trace ( trace2) ;
421
+ plot. add_trace ( trace3) ;
422
+ // Add traces to second subplot (x2, y2 axes)
423
+ plot. add_trace ( trace4) ;
424
+ plot. add_trace ( trace5) ;
425
+
426
+ let layout = Layout :: new ( )
427
+ . title ( "Subplots with Multiple Traces" )
428
+ . grid (
429
+ LayoutGrid :: new ( )
430
+ . rows ( 1 )
431
+ . columns ( 2 )
432
+ . pattern ( GridPattern :: Independent ) ,
433
+ ) ;
434
+ plot. set_layout ( layout) ;
435
+
436
+ let path = write_example_to_html ( & plot, file_name) ;
437
+ if show {
438
+ plot. show_html ( path) ;
439
+ }
440
+ }
441
+ // ANCHOR_END: subplots_with_multiple_traces
442
+
389
443
fn main ( ) {
390
444
// Change false to true on any of these lines to display the example.
391
445
// Subplots
@@ -404,6 +458,9 @@ fn main() {
404
458
405
459
many_subplots_with_titles ( false , "many_subplots_with_titles" ) ;
406
460
461
+ // Multiple traces in subplots
462
+ subplots_with_multiple_traces ( false , "subplots_with_multiple_traces" ) ;
463
+
407
464
// Multiple Axes
408
465
two_y_axes ( false , "two_y_axes" ) ;
409
466
multiple_axes ( false , "multiple_axes" ) ;
0 commit comments