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] Weird behavior with Jupyter Rust kernel and plotters #661

Open
stjepangolemac opened this issue Nov 25, 2024 · 0 comments
Open

[BUG] Weird behavior with Jupyter Rust kernel and plotters #661

stjepangolemac opened this issue Nov 25, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@stjepangolemac
Copy link

Describe the bug
Jupyter doesn't display the plot properly if the data that goes into the LineSeries is borrowed.

To Reproduce

:dep plotters = { version = "^0.3.5", default_features = false, features = ["evcxr", "all_series", "all_elements"] }
use plotters::prelude::*;

let points: Vec<(f64, f64)> = (0..1000).map(|i| i as f64).map(|i| (i, (i * 0.1).cos())).collect();

evcxr_figure((640, 240), |root| {
    root.fill(&WHITE)?;
    
    let min_x = points.iter().map(|(x, _)| x).min_by(|a, b| a.partial_cmp(b).unwrap()).copied().unwrap();
    let max_x = points.iter().map(|(x, _)| x).max_by(|a, b| a.partial_cmp(b).unwrap()).copied().unwrap();
    let min_y = points.iter().map(|(_, y)| y).min_by(|a, b| a.partial_cmp(b).unwrap()).copied().unwrap();
    let max_y = points.iter().map(|(_, y)| y).max_by(|a, b| a.partial_cmp(b).unwrap()).copied().unwrap();

    let mut chart = ChartBuilder::on(&root)
        .margin(5)
        //.caption("BTC Price", ("sans-serif", 20))
        .x_label_area_size(30)
        .y_label_area_size(30)
        .build_cartesian_2d(min_x..max_x, min_y..max_y)?;

    chart.configure_mesh().draw()?;
    
    chart.draw_series(LineSeries::new(
        points.clone(),
        &RED,
    ))?;
    
    Ok(())
})

This shows the correct plot.

image

But, if I remove the .clone() when creating the line series the plot is gone and I see only raw HTML / SVG.

EVCXR_END_CONTENT
EVCXR_BEGIN_CONTENT text/html
<div style=""><svg width="640" height="240" viewBox="0 0 640 240" xmlns="http://www.w3.org/2000/svg">
<rect x="0" y="0" width="640" height="240" opacity="1" fill="#FFFFFF" stroke="none"/>
<line opacity="0.1" stroke="#000000" stroke-width="1" x1="35" y1="204" x2="35" y2="5"/>
<line opacity="0.1" stroke="#000000" stroke-width="1" x1="40" y1="204" x2="40" y2="5"/>
<line opacity="0.1" stroke="#000000" stroke-width="1" x1="46" y1="204" x2="46" y2="5"/>
<line opacity="0.1" stroke="#000000" stroke-width="1" x1="52" y1="204" x2="52" y2="5"/>
<line opacity="0.1" stroke="#000000" stroke-width="1" x1="58" y1="204" x2="58" y2="5"/>
<line opacity="0.1" stroke="#000000" stroke-width="1" x1="64" y1="204" x2="64" y2="5"/>
<line opacity="0.1" stroke="#000000" stroke-width="1" x1="70" y1="204" x2="70" y2="5"/>
<line opacity="0.1" stroke="#000000" stroke-width="1" x1="76" y1="204" x2="76" y2="5"/>
<line opacity="0.1" stroke="#000000" stroke-width="1" x1="82" y1="204" x2="82" y2="5"/>
<line opacity="0.1" stroke="#000000" stroke-width="1" x1="88" y1="204" x2="88" y2="5"/>
...

Why is that?

Version Information
^0.3.5

Cross posted here.

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

1 participant