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

[BUG] Surprising plotting behavior when point is out of range. #656

Open
yygrechka opened this issue Oct 26, 2024 · 4 comments
Open

[BUG] Surprising plotting behavior when point is out of range. #656

yygrechka opened this issue Oct 26, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@yygrechka
Copy link

Describe the bug
I've been playing around with the plotters library and even creating my own utility crate using it, and I was surprised to see that when a point is out of range of the plotting area, it is drawn somewhere close to the edge of the plotting area (the expected behavior would be that it is not drawn at all). I would say that this causes the plot to be "incorrect" and thus qualifies as a "BUG".
Screenshot from 2024-10-26 11-48-55

To Reproduce
In a jupyter notebook:

1st cell:

:dep plotters = { version = "0.3.7", defualt_features=false, features=["evcxr", "all_series"]}
use plotters::prelude::*;

2nd cell:

let points1 = vec![0.2, 0.4, 0.6, 0.8];
let points2 = vec![0.2, 0.9, 1.6, 2.3];

evcxr_figure((640, 480), |root| {
    // The following code will create a chart context

    let (up, down) = root.split_vertically(240);
    let mut chart = ChartBuilder::on(&up)
        .caption("(Incorrect) Should be linear; points do not fit into chart and are forced into it", ("Arial", 20).into_font())
        .x_label_area_size(40)
        .y_label_area_size(40)
        .build_cartesian_2d(0f64..1f64, 0f64..1f64)?;
    
    chart.configure_mesh()
        .disable_x_mesh()
        .disable_y_mesh()
        .draw()?;
    
    chart.draw_series(points1.iter().zip(points2.iter()).map(|(x,y)| Circle::new((*x,*y), 3, RED.filled())));


    let mut chart = ChartBuilder::on(&down)
        .caption("(Correct) Linear relationship; points fit into chart", ("Arial", 20).into_font())
        .x_label_area_size(40)
        .y_label_area_size(40)
        .build_cartesian_2d(0f64..1f64, 0f64..3f64)?;
    
    chart.configure_mesh()
        .disable_x_mesh()
        .disable_y_mesh()
        .draw()?;
    
    chart.draw_series(points1.iter().zip(points2.iter()).map(|(x,y)| Circle::new((*x,*y), 3, RED.filled())));

    
    Ok(())
}).style("width:60%")

Version Information
plotters version 0.3.7

@yygrechka yygrechka added the bug Something isn't working label Oct 26, 2024
@yygrechka
Copy link
Author

Seems very related to:
#622

and
khonsulabs/cushy#179

@yygrechka
Copy link
Author

Attempted the following import:

:dep plotters = { git = "https://github.com/plotters-rs/plotters", branch = "master", defualt_features=false, features=["evcxr", "all_series"] } 
use plotters::prelude::*;

Got the same behavior.

@mchant
Copy link

mchant commented Dec 1, 2024

@yygrechka,
Could you add a filter?
instead of
chart.draw_series(points1.iter().zip(points2.iter()).map(|(x,y)| Circle::new((*x,*y), 3, RED.filled())));
do
chart.draw_series(points1.iter().zip(points2.iter()).filter(|(x,y)| **y < 1f64).map(|(x,y)| Circle::new((*x,*y), 3, RED.filled())));

@jbncode
Copy link

jbncode commented Dec 1, 2024

@mchant
Adding a filter works easily for points, but is more complicated for lines, see e.g. #429

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

3 participants