matplotlib-cpp icon indicating copy to clipboard operation
matplotlib-cpp copied to clipboard

Incorrect plot when arguments are blocks of an Eigen::Matrix

Open Lavinius opened this issue 4 years ago • 1 comments

If I declare an

Eigen::Matrix _2D_data; /* The initialization does not matter. The first row holds the x-coordinates, and the second row holds the y- coordinates. */

and I want to call

plt::plot(_2D_data.row(1), _2D_data.row(2));

the resulting plot will not be correct. Around 50% of the points will have their coordinates reversed (the x-coordinates will become y-coordinates and vice-versa).

To correctly plot, I have to write:

Eigen::VectorX x_coords{ _2D_data.row(0) }; Eigen::VectorX y_coords{ _2D_data.row(1) };

plt::plot(x_coords, y_coords);

Thanks for the otherwise great library!

Lavinius avatar Jan 17 '22 14:01 Lavinius

Hi @Lavinius, thanks for reporting this! Feel free to submit a PR to address this issue, I didn't touch the code in a long time and it would probably take me a bit longer than you 😉

Cryoris avatar Jan 18 '22 12:01 Cryoris