diff --git a/examples/subplots/src/main.rs b/examples/subplots/src/main.rs index 18aee5ac..d96616a0 100644 --- a/examples/subplots/src/main.rs +++ b/examples/subplots/src/main.rs @@ -29,6 +29,50 @@ fn simple_subplot() { plot.show(); } +fn simple_subplot_matches_x_axis() { + let trace1 = Scatter::new(vec![1, 2, 3], vec![4, 5, 6]).name("trace1"); + let trace2 = Scatter::new(vec![20, 30, 40], vec![50, 60, 70]) + .name("trace2") + .x_axis("x2") + .y_axis("y2"); + + let mut plot = Plot::new(); + plot.add_trace(trace1); + plot.add_trace(trace2); + + let layout = Layout::new().x_axis(Axis::new().matches("x2")).grid( + LayoutGrid::new() + .rows(1) + .columns(2) + .pattern(GridPattern::Independent), + ); + plot.set_layout(layout); + + plot.show(); +} + +fn simple_subplot_matches_y_axis() { + let trace1 = Scatter::new(vec![1, 2, 3], vec![4, 5, 6]).name("trace1"); + let trace2 = Scatter::new(vec![20, 30, 40], vec![50, 60, 70]) + .name("trace2") + .x_axis("x2") + .y_axis("y2"); + + let mut plot = Plot::new(); + plot.add_trace(trace1); + plot.add_trace(trace2); + + let layout = Layout::new().y_axis(Axis::new().matches("y2")).grid( + LayoutGrid::new() + .rows(1) + .columns(2) + .pattern(GridPattern::Independent), + ); + plot.set_layout(layout); + + plot.show(); +} + fn custom_sized_subplot() { let trace1 = Scatter::new(vec![1, 2, 3], vec![4, 5, 6]).name("trace1"); let trace2 = Scatter::new(vec![20, 30, 40], vec![50, 60, 70]) @@ -289,6 +333,8 @@ fn main() { // Subplots // simple_subplot(); + // simple_subplot_matches_x_axis(); + // simple_subplot_matches_y_axis(); // custom_sized_subplot(); // multiple_subplots(); // stacked_subplots(); diff --git a/plotly/src/layout/mod.rs b/plotly/src/layout/mod.rs index 6ea1e16f..d0d53f8d 100644 --- a/plotly/src/layout/mod.rs +++ b/plotly/src/layout/mod.rs @@ -546,10 +546,8 @@ impl Axis { Default::default() } - pub fn matches(mut self, matches: bool) -> Self { - if matches { - self.matches = Some(String::from("x")); - } + pub fn matches(mut self, matches: &str) -> Self { + self.matches = Some(matches.to_string()); self } @@ -2444,7 +2442,7 @@ mod tests { .n_ticks(600) .tick0(5.0) .dtick(10.0) - .matches(true) + .matches("x") .tick_values(vec![1.0, 2.0]) .tick_text(vec!["one".to_string(), "two".to_string()]) .ticks(TicksDirection::Inside)