Skip to content

Custom color scale #296

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

Open
battleoftwok opened this issue May 25, 2025 · 2 comments
Open

Custom color scale #296

battleoftwok opened this issue May 25, 2025 · 2 comments

Comments

@battleoftwok
Copy link

battleoftwok commented May 25, 2025

Is it possible to create a unique color scale that does not depend on the objects on the graph? The thing is that I just color the objects using my own linear interpolation, so I just need to specify the scale itself. Can I create it separately and place it anywhere?

fn custom_result(
    result: &Matrix<f32, Dyn, Const<1>, VecStorage<f32, Dyn, Const<1>>>,
    triangles: &Vec<Elist>,
    nodes: &Vec<Nlist>,
    gradient: &LinearGradient,
    plot: &mut Plot,
) {
    let T_MAX = result.max();
    let T_MIN = result.min();

    for elem in triangles {
        let node_i = &nodes[elem.node_i - 1];
        let node_j = &nodes[elem.node_j - 1];
        let node_k = &nodes[elem.node_k - 1];

        let T1 = result[node_i.node - 1];
        let T2 = result[node_j.node - 1];
        let T3 = result[node_k.node - 1];

        let temperature = (T1 + T2 + T3) / 3.0;

        let trace = Scatter::new(
            vec![node_i.x, node_j.x, node_k.x],
            vec![node_i.y, node_j.y, node_k.y],
        )
        .x_axis("x2")
        .y_axis("y2")
        .mode(Mode::None)
        .name(temperature.to_string())
        .show_legend(false)
        .fill_color(
            gradient
                .at(interpolate(temperature, T_MIN, T_MAX))
                .to_hex_string(),
        )
        .fill(Fill::ToSelf);

        plot.add_trace(trace);
    }
}
@andrei-ng
Copy link
Collaborator

@battleoftwok, TBH I don't understand the problem. Is it something that is missing in this implementation compared with Python?

For example, if you look at the Python docs, is there an example you have of what you are trying to achieve?
https://plotly.com/python/colorscales/

@battleoftwok
Copy link
Author

battleoftwok commented May 31, 2025

The code presented above generates this temperature field. There is nothing like this in the examples. I just need a scale next to it, and as I understand it, it is not added separately. Maybe there is a way to create an empty label in which there will be no heatmap but only one scale?

Image

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

No branches or pull requests

2 participants