Why the plot generated with the spy command has a restrictive aspect ratio for long/tall matrices in R2021b?

11 views (last 30 days)
When I create a SPY plot for a sparse matrix that has a lot more columns than rows, I get a plot which is very small and hard to use. For example if a matrix is of size 3 x 600, I get a plot similar to the following.
% Create random sparse matrix
z = rand(3,600);
z(z<.9) = 0;
z = sparse(z);
spy(z)
I cannot zoom in or expand the axes to see the structure in the matrix. 
How to enhance this plot?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Nov 2021
SPY uses the size of the input matrix to adjust the plot box's aspect ratio. For tall or thin matrices, this gives you the behavior from your plot. Change the aspect ratio back to something closer to 1-to-1 to "undo" this.
spy(z); set(gca, 'PlotBoxAspectRatio', [1 1 1])
You can use this as a workaround. If you do, you're probably also going to want to adjust the marker size for the SPY plot a bit larger as well.

More Answers (0)

Categories

Find more on Discrete Data Plots in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!