MathGroup Archive 2001

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

Search the Archive

RE: plot matrix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg27759] RE: [mg27713] plot matrix
  • From: "David Park" <djmp at earthlink.net>
  • Date: Wed, 14 Mar 2001 04:06:58 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Here is a sample matrix that contains values corresponding to Sin[x y];

mat = Table[Sin[x*y], {x, -Pi, Pi, Pi/100}, {y, -Pi, Pi, Pi/100}];

The matrix can be plotted using the Raster primitive.

Show[Graphics[{Raster[mat, ColorFunction -> Hue]}],
   AspectRatio -> Automatic, Frame -> True, FrameLabel -> {x, y},
   PlotLabel -> "Sample Array Plot", ImageSize -> 500];

The only problem is that the x and y axes go from 0 to 200 because the
matrix is 200x200 elements. You may have some actual physical scale that you
wish to use for the x and y axes. In my sample matrix I would really like
the tick marks to go from -Pi to Pi. You can do this using FrameTicks and
making a table of tick locations and values. I have a package, at my web
site below, which makes this easier to do. It is part of the DrawingPaper
packages but can be used by itself without any of the other packages.

Needs["Graphics`DrawingTicksAndGrids`"]

?CustomTicks
\!\("CustomTicks[inversefunction, tickspecs, options] will generate custom \
tick marks. If the normal axes is given by the variable u, but is to labeled
\
by v = f[u] then the inverse function \!\(f\^\(-1\)\) must be supplied as a
\
pure function. If a linear scale is to be used, tickspecs will take the
form: \
{start, end, inc, subdivisions}. subdivisions of n will provide n-1
unlabeled \
tick marks between each labeled tick mark. If a log scale is to be used, \
tickspecs will take the form {startpower, endpower, vals, subvals} where
vals \
and subvals are the lists of the labeled and unlabeled values in one decade.
\
The labeled ticks will be \!\(10\^power\) vals where power ranges from the \
start to end value. Mathematica will eliminate any ticks which are outside \
the PlotRange.\n\nThe options for CustomTicks are:CTNumberFunction, \
CTTickSpecs, CTTickStyle, CTUnLabTickSpecs, CTUnLabTickStyle. See their
usage \
messages."\)

We can calculate a pure function which gives the plot coordinate for the
tick label we want by:

u[v_] := a + b*v;
eqns = {u[-Pi] == 1/2, u[Pi] == 199 + 1/2};
absols = Solve[eqns, {a, b}][[1]];
uvfunction = Function @@ {u[#1] /. absols}
100 + (199*#1)/(2*Pi) &

The value of -Pi corresponds to the middle of the first column which occurs
at the plot coordinate 0.5 and the value of Pi corresponds to the middle of
the last column which occurs at the plot coordinate 199.5.

Now we can generate labeled tick marks for the bottom and left hand side of
the frame, and unlabeled tick marks for the other two sides.

labeledtickmarks = CustomTicks[uvfunction, {-Pi, Pi, Pi/4, 4}];
plaintickmarks = CustomTicks[uvfunction, {-Pi, Pi, Pi/4, 4},
    CTNumberFunction -> ("" & )];

Finally, we can display the plot with the proper tick labels.

Show[Graphics[{Raster[mat, ColorFunction -> Hue]}],
   AspectRatio -> Automatic, Frame -> True, ImageSize -> 500,
   FrameTicks -> {labeledtickmarks, labeledtickmarks, plaintickmarks,
     plaintickmarks}, FrameLabel -> {x, y},
   PlotLabel -> "Sample Array Plot"];

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/


> From: Su Su Win [mailto:susuwin at post.kek.jp]
To: mathgroup at smc.vnet.net
> I have a big matrix of (4095 rows x 1280 column).
> I want to plot those data in 3D graph just like listplot in both
> directions.
> How shall i do for the x and y axis?
> best, win
>



  • Prev by Date: Re: Best code to match corresponding list items?
  • Next by Date: RE: Re: Question involving scope/recursion/arguments
  • Previous by thread: Re: plot matrix
  • Next by thread: Direct product of two matrices