Search code examples
excelmatlabxmgrace

Scatter plot for every pairs in a two column matrix


I have a matrix which contains the atom numbers of the pairs of atoms which are in contact with each other. My matrix is like this:

column 1: atom number i;
column 2: atom number j

i,j runs from 1 to 800.

If there is a pair i-j in the matrix, place a dot corresponding to the position (i,j) of the matrix. How do I plot such matrix?

Example:

A= [1,3; 3,8; 3,1; 6,2; 2,6; 1,2; 5,2; 8,3; 2,5; 2,1]

I want to Plot the matrix A, where X and Y-axis run from 1 to 8. Place a dot for every combination of X and Y which are present in A.

I want a plot like this:

I want a plot like this.


Solution

  • Isn't this just a scatter plot?

    If your m x 2 matrix is saved in a text file then this is trivial. Here are the contents of an example data file "input.dat":

    4 3
    3 4
    5 3
    3 5
    8 2
    2 8
    

    All you need to do is open the data file in xmgrace using xmgrace input.dat. Now, initially it will be a line plot, but if you do 'Plot' > 'Set Appearance' and then with the only set already being selected you can set the 'Symbol Properties' 'Type:' to Diamond and 'Line Properties' 'Type:' to None you will already be on your way. Setting the symbol fill to solid red, tweaking the axis ranges and showing major tick grid lines will give a plot like the one you gave as an example.

    enter image description here

    You can save a parameters file and in future load the parameters at the beginning using

    xmgrace -param template.par input2.dat.

    But, having said all this, why not just plot it in matlab?