Search code examples
matlabmatrixplotsparse-matrixaxis-labels

Matlab: axis command to control spy command's axis labeling for a sparse matrix?


The data has 12 rows and, instead of the N-th row 1...12, the plot should have a column going from 6...89 like the first column of the data. Then the X-coordinate is for the other two rows. The docs about spy mentions nothing about the axis so tried the following but not working

>> spy(C(neg,:))
>> axis([1 31 6 89]); spy(C(neg,:))                  #xmin xmax ymin ymax
>> axis on; axis([1 31 6 89]); spy(C(neg,:))
>> axis on; a=spy(C(neg,:)); axis(a,[1 31 6 89]);
Error using spy
Too many output arguments.

so

How to visualise the sparse data with rightly-labelled axis?

Example

Data

6   2   7
11  4   7
26  9   7
36  12  7
44  15  7
55  21  7
60  16  11  7
62  23  7
86  28  7
87  27  7
89  25  11  7

This plot shows the vertical labels wrongly 0 2 4 ... 12 instead of 6 7 ... 89

enter image description here


Solution

  • The problem with the expression such as C([10,20,100],:) is that it will change your Y-axis so your original 10 will be one, the original 20 will be 2 and the original 100 will be 3 on the y-axis. The trick is not to take things out because Matlab will redefine the axis so create a new variable CC where you redefine the unwanted things to zero and then as Masi mentioned use the axis -- after the spy command!

    Example

    enter image description here