`Spy` function behavior with sparse matrices

I am trying to generate sparsity patterns for some matrices for a project. However, I cannot seem to find the necessary command to make all the sparsity patterns the same size. Below is an example and the output:

A = sprand(20,20,.05)
mat1 = spzeros(50,50)
mat1[31:50,31:50] = A 
mat2 = spzeros(50,50)
mat2[1:20,1:20] = A 
display(spy(mat1))
display(spy(mat2))

The first plot has the axes start at 31 to 50 on both dimensions, and the first is 1 to 20 and 1 to 20. However, I want both to be from 1 to 50. I tried searching around for the needed option, but I could not locate any so I am making a post.

Here are screenshots of my output:

image

image

Thanks!

You just need to set the xlims and ylims. I assume this is Plots?
Try:

A = sprand(20,20,.05)
mat1 = spzeros(50,50)
mat1[31:50,31:50] = A 
mat2 = spzeros(50,50)
mat2[1:20,1:20] = A
display(xlims!(ylims!(spy(mat1), (1,50)), (1,50)))
display(xlims!(ylims!(spy(mat2), (1,50)), (1,50)))
1 Like

Yes! Thank you.