8000 Weird behavior with Jupyter Rust kernel and plotters · Issue #387 · evcxr/evcxr · GitHub 8000
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Weird behavior with Jupyter Rust kernel and plotters #387
Open
@stjepangolemac

Description

@stjepangolemac

Reproduction code:

: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=
52DA
"#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?

Cross posted here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0