MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to convert a matrix into a graph?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg37791] Re: How to convert a matrix into a graph?
  • From: Tom Burton <tburton at brahea.com>
  • Date: Wed, 13 Nov 2002 01:11:02 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Hello,

On 11/12/02 12:16 AM, in article aqqdcu$sec$1 at smc.vnet.net, "Jia Guo"
<jiaguo at uiuc.edu> wrote:

> 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.

This may do what you want:

matrix=Table[Random[],{100},{100}];

Show[Graphics[{
  PointSize[0.0075],
  MapIndexed[{GrayLevel[#1],Point[#2]}&, matrix, {2}]
}, AspectRatio->Automatic, PlotRange->All]]

Here the row number increases to the right and column number increases from
bottom to top. You can Transpose and Reverse matrix as needed to get the
orientation you want. For example, this

Show[Graphics[{
  PointSize[0.0075],
  MapIndexed[{GrayLevel[#1],Point[#2]}&,  Transpose[Reverse[matrix]], {2}]
}, AspectRatio->Automatic, PlotRange->All]]

will orient the graph the same way that a matrix is usually printed, with
rows increasing down ane columns increasing right.

Tom Burton


Tom Burton



  • Prev by Date: Re: Export: Where is exported file?
  • Next by Date: RE: Export: Where is exported file?
  • Previous by thread: RE: How to convert a matrix into a graph?
  • Next by thread: Re: How to convert a matrix into a graph?