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

[bug] disable_y_axis function does nothing #250

Closed AleksLitynski closed 3 years ago

AleksLitynski commented 3 years ago

The function https://docs.rs/plotters/0.3.0/plotters/chart/struct.MeshStyle.html#method.disable_y_axis doesn't seem to do anything.

This is the code I'm testing with:

use plotters::prelude::*;

fn main() {
    let root = BitMapBackend::new("example.png", (1000, 700))
        .into_drawing_area();

    root.fill(&WHITE).unwrap();

    let mut chart = ChartBuilder::on(&root)
        .set_label_area_size(LabelAreaPosition::Left, 40)
        .set_label_area_size(LabelAreaPosition::Bottom, 40)
        .build_cartesian_2d(0..7, 0..50)
        .unwrap();

    chart.configure_mesh()
        .disable_y_axis()
        .draw().unwrap();

    let data: Vec<(i32, i32)> = vec![
        (0, 10),
        (1, 15),
        (2, 20),
        (3, 25),
        (4, 30),
        (5, 35),
        (6, 40),
    ];

    chart.draw_series(data.iter().map(|(x, y)| {
        let mut bar = Rectangle::new([
            (*x, *y),
            (*x + 1, 0)],
            BLUE.filled());
        bar.set_margin(0, 0, 15, 15);
        bar
    }))
    .unwrap();
}

When I call .disable_y_axis, this is the output: example

When I comment out .disable_y_axis, this is the output: example

38 commented 3 years ago

Hi there, thanks for using plotters!

That's a good catch! In fact, disable_y_axis has some effect. The first plot doesn't have y axis drawn, however, the value label is still there. This is definitely not expected result. I got the fix on master branch (fb154e6) and will make it available in next minor release.

Feel free to try the master branch and if you feel anything is not correct, please reopen the issue.

Thanks again for the help, cheers!