RustGnuplot
RustGnuplot copied to clipboard
plotting matrices with image in 2D
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):
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