Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Y labels are not aligned #550

Open
wangjiawen2013 opened this issue Feb 19, 2024 · 1 comment
Open

Y labels are not aligned #550

wangjiawen2013 opened this issue Feb 19, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@wangjiawen2013
Copy link

Hi,
When plotting both the left and right y-axis, the labels on the left y-axis was not aligned:

evcxr_figure((640, 480), |root| {
    let x_axis = (-3.4f32..3.4).step(0.01);
    root.fill(&WHITE)?;
    let mut chart = ChartBuilder::on(&root).margin(1)
        .set_all_label_area_size(50)
        .build_cartesian_2d(-3.4f32..3.4, -1.2f32..1.2f32)?;

    chart.configure_mesh().x_labels(20).y_labels(10).disable_mesh()
        .x_desc("X")
        .y_desc("Y")
        .label_style(("sans-serif", 20, &BLACK))
        .x_label_formatter(&|v| format!("{:.1}", v))
        .y_label_formatter(&|v| format!("{:.1}", v))
        .draw()?;
    chart.draw_series(LineSeries::new(x_axis.values().map(|x| (x, x.sin())), &RED))?
        .label("sin")
        .legend(|(x, y)| PathElement::new(vec![(x,y), (x+20,y)], &RED)); 
    chart.draw_series(LineSeries::new(x_axis.values().map(|x| (x, x.cos())), &BLUE))?
        .label("cos")
        .legend(|(x, y)| PathElement::new(vec![(x,y), (x+20,y)], &BLUE));
    chart.configure_series_labels()
        .margin(10)
        .position(SeriesLabelPosition::UpperLeft)
        .border_style(&BLACK)
        .label_font(("Calibri", 20))
        .draw()?;
    Ok(())
}).style("width:60%")

here is the result, it seems that the alignment of right y-axis are affected by the negative sign:
image

@wangjiawen2013 wangjiawen2013 added the bug Something isn't working label Feb 19, 2024
@wangjiawen2013 wangjiawen2013 changed the title x labels are not aligned Y labels are not aligned Feb 19, 2024
@wangjiawen2013
Copy link
Author

And here is another example:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant