@@ -386,6 +386,58 @@ fn many_subplots_with_titles(show: bool, file_name: &str) {
386386}
387387// ANCHOR_END: many_subplots_with_titles
388388
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 ( ) . title ( "Subplots with Multiple Traces" ) . grid (
427+ LayoutGrid :: new ( )
428+ . rows ( 1 )
429+ . columns ( 2 )
430+ . pattern ( GridPattern :: Independent ) ,
431+ ) ;
432+ plot. set_layout ( layout) ;
433+
434+ let path = write_example_to_html ( & plot, file_name) ;
435+ if show {
436+ plot. show_html ( path) ;
437+ }
438+ }
439+ // ANCHOR_END: subplots_with_multiple_traces
440+
389441fn main ( ) {
390442 // Change false to true on any of these lines to display the example.
391443 // Subplots
@@ -404,6 +456,9 @@ fn main() {
404456
405457 many_subplots_with_titles ( false , "many_subplots_with_titles" ) ;
406458
459+ // Multiple traces in subplots
460+ subplots_with_multiple_traces ( false , "subplots_with_multiple_traces" ) ;
461+
407462 // Multiple Axes
408463 two_y_axes ( false , "two_y_axes" ) ;
409464 multiple_axes ( false , "multiple_axes" ) ;
0 commit comments