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

changed the expected type for HeatMap.z from Option<Vec<Z>> to Option<Vec<Vec<Z>>> #157

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tectin0
Copy link
Contributor

@tectin0 tectin0 commented Sep 4, 2023

With Vec<Vec<T>> as an input for HeatMap.z it infers that Z has the type Vec<T> instead of T. This prevents .zmin() and .zmax() from working.

Example:

use plotly::common::{ColorScalePalette, Font, Title};

use plotly::{HeatMap, Layout, Plot};

fn main() {
    let x = (0..100).map(|x| x as f64).collect::<Vec<f64>>();
    let y = (0..100).map(|y| y as f64).collect::<Vec<f64>>();
    let z: Vec<Vec<f64>> = x
        .iter()
        .map(|x| {
            y.iter()
                .map(|y| (x / 5.0).powf(2.0) + (y / 5.0).powf(2.0))
                .collect::<Vec<f64>>()
        })
        .collect::<Vec<Vec<f64>>>();

    let colorscale = ColorScalePalette::Jet;

    let trace = HeatMap::new(x, y, z)
        .zmin(400.0) // does not work expects a Vec<f64>
        .zmax(600.0) // same here
        .color_scale(colorscale.into());

    let layout = Layout::new().font(Font::new().size(32));

    let mut plot = Plot::new();
    plot.set_layout(layout);
    plot.add_trace(trace);

    plot.show();
}

Changing the type to Option<Vec<Vec<Z>> results in a correctly inferred type of Z and .zmin() and .zmax() work correctly

newplot

also added customized_heat_map function to showcase the working zmin and zmax

added `customized_heat_map` function to showcase the working zmin and zmax
@tectin0
Copy link
Contributor Author

tectin0 commented Sep 4, 2023

Going to look into the failed tests

@tectin0 tectin0 marked this pull request as draft September 4, 2023 16:10
@tectin0 tectin0 marked this pull request as ready for review September 22, 2023 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant