plotters-rs / plotters

A rust drawing library for high quality data plotting for both WASM and native, statically and realtimely 🦀 📈🚀
https://plotters-rs.github.io/home/
MIT License
3.85k stars 278 forks source link

[BUG] Code hangs when configuring 2nd axis on raspberry pi #152

Closed brownjohnf closed 2 years ago

brownjohnf commented 4 years ago

Describe the bug

I have what seems like a fairly basic plot I'm trying to do, with 2 time series with different y axes. Everything works fine with a single y axis, but if I attempt to configure the 2nd y axis, the code hangs at that point. I'm working on getting a better sense of what's going on via strace, etc., but this only occurs when I run this code on a raspberry pi. On my workstation (x86_64) everything works just fine.

I'm also working on getting a more minimal reproduction, but it's a really slow process because I'm deploying in a container to a stripped down OS, so I can't actually just build the source locally easily. I wanted to post this here in case it's a stupid user error, or a known issue.

To Reproduce

    // Create a path where we'll store the image.
    let path = PathBuf::from(format!("/tmp/{}.png", Utc::now().timestamp_nanos()));

    // Set up our backend.
    let root = BitMapBackend::new(&path, (320, 175)).into_drawing_area();

    // Set the background color.
    root.fill(&WHITE)?;

    // Set up a chart builder in the root.
    let mut chart = ChartBuilder::on(&root)
        .margin(3)
        .x_label_area_size(15)
        .y_label_area_size(30)
        .right_y_label_area_size(30)
        .build_ranged(temp_domain, temp_range)?
        .set_secondary_coord(ror_domain, ror_range);

    // Set the mesh background in the builder.
    chart
        .configure_mesh()
        .disable_mesh()
        .x_label_formatter(&|l| format!("{}:{:02}", l / 60, l % 60))
        .x_labels(6)
        .y_label_formatter(&|l| format!("{:.0}", l))
        .y_desc("temp")
        .draw()?;

    /*
    // This is where the problem starts. This chain of functions seems to hang and never return.
    // With it commented out like this, the code works, but the second series doesn't show up on the plot.
    chart
        .configure_secondary_axes()
        .draw()?;
    */

    // Plot the second series.
    chart
        .draw_secondary_series(LineSeries::new(ror.iter().map(|(x, y)| (*x, *y)), &BLUE))?
        .label("RoR")
        .legend(|(x, y)| PathElement::new(vec![(x, y), (x + 10, y)], &BLUE));

    // Plot the first series.
    chart
        .draw_series(LineSeries::new(temp.iter().map(|(x, y)| (*x, *y)), &RED))?
        .label("temp")
        .legend(|(x, y)| PathElement::new(vec![(x, y), (x + 10, y)], &RED));

    // Label the series.
    chart
        .configure_series_labels()
        .draw()?;

Version Information

rust 1.43.1 plotters 0.2.15

I'm continuing to investigate this, and will post updates as I find anything. I think one of the most helpful things would be if anyone knows what behavior that configure_secondary_axes function might cause that would help me narrow down whether this is an issue with the OS/libs, ARM, etc.

Thanks for any help, and apologies that it's so vague.

38 commented 4 years ago

Hi there, sorry for the delay. Could you please provide more details? Especially ror_domain and ror_range

Currently, plotters have an issue with log scale f32 and f64 ranges, if the start point is 0 and this will causing the logical value map to -inf.

I am going to fix this, and if this is the cause, you probably can try to change any 0.0 to a very small value, e.g. 1e-5,etc

Thanks,

38 commented 2 years ago

Since I can't repo the bug, closing this issue, please let me know if there's still any issue