Skip to content

Commit d938206

Browse files
authored
Merge branch 'main' into table-pr
2 parents be0a496 + 4815df7 commit d938206

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

examples/subplots/src/main.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,50 @@ fn simple_subplot() {
2929
plot.show();
3030
}
3131

32+
fn simple_subplot_matches_x_axis() {
33+
let trace1 = Scatter::new(vec![1, 2, 3], vec![4, 5, 6]).name("trace1");
34+
let trace2 = Scatter::new(vec![20, 30, 40], vec![50, 60, 70])
35+
.name("trace2")
36+
.x_axis("x2")
37+
.y_axis("y2");
38+
39+
let mut plot = Plot::new();
40+
plot.add_trace(trace1);
41+
plot.add_trace(trace2);
42+
43+
let layout = Layout::new().x_axis(Axis::new().matches("x2")).grid(
44+
LayoutGrid::new()
45+
.rows(1)
46+
.columns(2)
47+
.pattern(GridPattern::Independent),
48+
);
49+
plot.set_layout(layout);
50+
51+
plot.show();
52+
}
53+
54+
fn simple_subplot_matches_y_axis() {
55+
let trace1 = Scatter::new(vec![1, 2, 3], vec![4, 5, 6]).name("trace1");
56+
let trace2 = Scatter::new(vec![20, 30, 40], vec![50, 60, 70])
57+
.name("trace2")
58+
.x_axis("x2")
59+
.y_axis("y2");
60+
61+
let mut plot = Plot::new();
62+
plot.add_trace(trace1);
63+
plot.add_trace(trace2);
64+
65+
let layout = Layout::new().y_axis(Axis::new().matches("y2")).grid(
66+
LayoutGrid::new()
67+
.rows(1)
68+
.columns(2)
69+
.pattern(GridPattern::Independent),
70+
);
71+
plot.set_layout(layout);
72+
73+
plot.show();
74+
}
75+
3276
fn custom_sized_subplot() {
3377
let trace1 = Scatter::new(vec![1, 2, 3], vec![4, 5, 6]).name("trace1");
3478
let trace2 = Scatter::new(vec![20, 30, 40], vec![50, 60, 70])
@@ -289,6 +333,8 @@ fn main() {
289333

290334
// Subplots
291335
// simple_subplot();
336+
// simple_subplot_matches_x_axis();
337+
// simple_subplot_matches_y_axis();
292338
// custom_sized_subplot();
293339
// multiple_subplots();
294340
// stacked_subplots();

plotly/src/layout/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,8 @@ impl Axis {
546546
Default::default()
547547
}
548548

549-
pub fn matches(mut self, matches: bool) -> Self {
550-
if matches {
551-
self.matches = Some(String::from("x"));
552-
}
549+
pub fn matches(mut self, matches: &str) -> Self {
550+
self.matches = Some(matches.to_string());
553551
self
554552
}
555553

@@ -2444,7 +2442,7 @@ mod tests {
24442442
.n_ticks(600)
24452443
.tick0(5.0)
24462444
.dtick(10.0)
2447-
.matches(true)
2445+
.matches("x")
24482446
.tick_values(vec![1.0, 2.0])
24492447
.tick_text(vec!["one".to_string(), "two".to_string()])
24502448
.ticks(TicksDirection::Inside)

0 commit comments

Comments
 (0)