Re: How to convert a matrix into a graph?
- To: mathgroup at smc.vnet.net
- Subject: [mg37807] Re: How to convert a matrix into a graph?
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Wed, 13 Nov 2002 01:12:57 -0500 (EST)
- References: <aqqdcu$sec$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Jia,
There are many ways to do this - here is one.
First we need a scaling function to take the min to take the min of the
range ff values that will be met over series of matrices to 0 and its max
to 1.
sc = Interpolation[{{0, 0}, {15, 1}},
InterpolationOrder -> 1]
Now for the graphics coding:
ShowMatrix[mat_] :=
Module[{di, dj},
{d1, d2} = Dimensions[mat];
Show[Graphics[MapIndexed[{GrayLevel[sc[#1]],
PointSize[1/(2*d1)], Point[#2]} & ,
Reverse[mat], {2}], GridLines ->
{Table[n, {n, 1, d1}], Table[n, {n, 1, d2}]},
PlotRange -> {{0.5, d1 + 0.5}, {0.5, d2 + 0.5}},
Frame -> True,
(FrameTicks -> {{}, Table[{n, #2 - n + 1},
{n, 1, #2}], Table[{n, n}, {n, 1, #1}],
{}} & ) @@ Dimensions[mat],
AspectRatio -> Automatic]]
]
You might want to delete some of the features; especially if the dimensions
of the matrix are very big.
We could, for example, make the point sizes vary with the size of the matrix
entry or superimpose the entries on the points
A different approach would be to use Raster or use disks instead of points.
Check
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
"Jia Guo" <jiaguo at uiuc.edu> wrote in message
news:aqqdcu$sec$1 at smc.vnet.net...
> Hi,
>
> My problem is how a matrix can be converted into a graph so that each
> element in the matrix represents dot: The value of the element is
> corresponding to the darkness of the dot. The position of the element
> in the matrix is corresponding to the position of the dot in the
> graph.
>
> Thank you!
>
> Jia
>