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

plotting matrices with image in 2D #96

Open
SalahEddineGhamri opened this issue Mar 16, 2024 · 0 comments
Open

plotting matrices with image in 2D #96

SalahEddineGhamri opened this issue Mar 16, 2024 · 0 comments

Comments

@SalahEddineGhamri
Copy link

SalahEddineGhamri commented Mar 16, 2024

Currently, I am trying to plot an obstacle map using image function. I am not sure how to use the dimensions optional to rotate the matrix.

The following code is used:

let original_matrix = DMatrix::<i32>::from_row_slice(10, 14, &[
        0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 1, 0, 0, 0, 0 ,0 ,0 ,0, 0, 0,
        0, 0, 0, 0, 1, 0, 0, 0, 0 ,0 ,0 ,0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 1 ,0 ,0 ,0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 1 ,0 ,0 ,0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 1 ,0 ,0 ,0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 1 ,0 ,0 ,0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0
    ]);

    let obstacle_map = grid_map::Map::new(original_matrix, 3).unwrap();

    let flattened_map: Vec<_> = obstacle_map.transpose().iter().cloned().collect();

    let (height, width) = obstacle_map.shape();

    let dimensions = Some((0.0, 0.0, ((width - 1) as f64), -((height - 1) as f64 )));

    fg.clear_axes();

    fg.axes2d().image(flattened_map.clone(), height, width, dimensions, &[]);

the x axis is the column direction and the y axis is the rows direction. How ever the resultant image is the following (I am plotting two other points in the chart):

image

maybe, I am missing something, but I thought dimensions will rotate image to look as the numerical view of it.

I wan the image to look like this with same axis of the image above:
0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0 ,0 ,0 ,0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0 ,0 ,0 ,0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1 ,0 ,0 ,0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1 ,0 ,0 ,0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1 ,0 ,0 ,0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1 ,0 ,0 ,0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0

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

1 participant