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.88k stars 281 forks source link

x_label doesn't start correctly #302

Closed bobgates closed 2 years ago

bobgates commented 3 years ago

I'm not seeing what I expect when using x_labels(n). I appreciate that it gives a maximum of n labels, but it sometimes just doesn't label the left most point on the x-axis if the value is whole number.

From the demo code:

        let mut chart = builder
            .margin(30)
            .caption(format!("y=x^{}", 3.0), ("sans-serif", 16))
            .x_label_area_size(30)
            .y_label_area_size(30)
            .build_cartesian_2d(-1.0f32..1f32, -1.2f32..1.2f32)
            .unwrap();

        chart
            .configure_mesh()
            .x_labels(5)
            .draw()
            .unwrap();

This produces an x-axis from -1 to 1 with labels at -0.5, 0, 0,5 and 1.0 ie -1.0 is missing.

I can get what I want if I change the build_cartesian_2d to read:

       .build_cartesian_2d(-1.00001f32..1f32, -1.2f32..1.2f32)

or something similar. This ensures -1 is in the range. I'd like this simple case to be correctly handled if possible.

Version Information I'm using v0.3 of plotters, driving it using plotters-iced v0.1. (I can't get plotters v0.3.1 to work - it complains about "failed to select a version for 'web-sys'")

38 commented 2 years ago

I believe this is fixed by recent commits. Feel free to reopen it if the problem is still there.