plotters icon indicating copy to clipboard operation
plotters copied to clipboard

[BUG] Drawing off by a few px

Open jangernert opened this issue 5 years ago • 1 comments

Describe the bug At least with the CanvasBackend the drawing of the axis seems to be off a little. Some lines of the axis don't quite connect. Some overlap which looks bad with the default opacity of the line.

It seems like the thickness of the line is not taken into consideration when drawing.

canvas

Overlap:

Screenshot from 2020-07-19 15-28-39

Overlap and end of X-Axis a little too short:

Screenshot from 2020-07-19 15-29-05

Axis not quite connecting right at 0:

Screenshot from 2020-07-19 15-28-05

Top of Y-Axis not going all the way to the top

Screenshot from 2020-07-19 15-28-23

To Reproduce

let backend = CanvasBackend::new("canvas").unwrap();
let root = backend.into_drawing_area();

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

let mut chart = ChartBuilder::on(&root)
    .set_left_and_bottom_label_area_size(30)
    .margin(10)
    .build_ranged(0.0..2.0, 0.0..3.0)
    .unwrap();

chart
    .configure_mesh()
    .x_labels(3)
    .y_labels(2)
    .draw()
    .unwrap();

let data = (0..=20)
    .map(|x| x as f64 / 10.0)
    .map(|x| (x, x.powf(2.0) + 1.0));

chart.draw_series(
    AreaSeries::new(
        data.clone(),
        0.0,
        &RED.mix(0.2),
    )
    .border_style(&RED),
).unwrap();

chart.draw_series(
    data
        .map(|(x, y)| Circle::new((x, y), 3, BLUE.filled())),
).unwrap();

root.present().unwrap();

Version Information

plotters = "0.2"

jangernert avatar Jul 19 '20 13:07 jangernert

It seems like this is related to #128, specifically the fact that plotters tries to draw the lines at integer coordinates but when the backend supports float coordinates then we have to add 0.5 to the coordinates, otherwise we're drawing "between" pixels. See my PR in plotters-canvas for an attempt at fixing this.

Pascal-So avatar Feb 26 '22 17:02 Pascal-So