Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: ArrayPlot coordinates scaling for overlays

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109267] Re: ArrayPlot coordinates scaling for overlays
  • From: "David Park" <djmpark at comcast.net>
  • Date: Tue, 20 Apr 2010 05:49:04 -0400 (EDT)

With plot functions, WRI usually only lists the options that are special to
that plot on the Function help page. You can get the full list of options by
using:

Options[ArrayPlot]  

You asked if there was a neater way to do this. My apologies in advance if
this does not really interest you but Presentations has rather extensive
capabilities for the graphical representation of complex functions and I
assume that is your actual objective here. (And you might also get
suggestions for making nice complex plots within regular Mathematica.) This
material should also appear within a few days in an archive kindly
maintained by Peter Lindsay of the Mathematics Department at St. Andrew`s
University. It contains the Mathematica notebooks addressing some problem
and a PDF for those who don't have Presentations or Mathematica.

http://blackbook.mcs.st-and.ac.uk/~Peter/djmpark/html/ 


Needs["Presentations`Master`"]

First, here is your plot done in Presentations. Instead of making separate
plots and combining them with a Show statement. You can simply combine all
the graphical elements in a single Draw2D statement.

arraydata = 
  Table[With[{z = x + I y}, 
    With[{w = (1 + z + z^2 + z^3)/(1 + z + z^2)}, Abs[w]]], {y, -1, 1,
     0.1}, {x, -1, 1, 0.1}];
Draw2D[
 {Opacity[.5],
  ArrayDraw[arraydata, ColorFunction -> "TemperatureMap", 
   DataRange -> {{-1, 1}, {-1, 1}}],
  Opacity[1], Arrowheads[Medium],
  Arrow[{{0, 0}, {1, 1}}]},
 ImageSize -> 250] 

Presentations has a feature, OptionsFinder, making it easy to get option
information and insert it into functions. This was contributed by Thomas
Munch and Syd Geraghty. In the above statement, you can place your cursor
after ArrayDraw and click the OptionsFinder. This brings up a new palette
that contains all the options for ArrayDraw. It has tooltips that show the
default value for each option. It also has a link to the help page for the
option and a tooltip giving the option usage message. It also has a link to
the function. If you click an option, it will be pasted into the statement
at the end and the default option value will be highlighted so one can
immediately type the desired option value. This is all very useful for using
options and getting into help for a function and its options. It is also a
little simpler in Presentations because ArrayDraw has fewer options than
ArrayPlot, containing only those options that affect the resulting
primitives and not the overall plot.

Next let's look at a couple of graphical representations of the function.

The first representation is a contour plot of the modulus of the function.
The ComplexCartesianContour primitive was used to draw the function.
Specific contour values are chosen so that the modulus is well represented
around both the poles and the zeros. Since the contour spacing's are
distinctly non-uniform, the Presentations ContourColors color function is
used to give distinct colors for each contour region. (Otherwise most of the
graphic would just be blue with a small red region as above.) Notice that we
need only one iterator with the min and max values specified by complex
numbers. I adjusted the domain to display the region of most interest. The
contours have tooltips displaying the contour values.

With[
 {f = Function[z, (1 + z + z^2 + z^3)/(1 + z + z^2)],
  zmin = -1.5 (1.25 + I),
  zmax = (.8 + 1.5 I),
  contourlist = {0, 0.1, .3, .5, .7, .9, 1, 1.4, 2, 3, 5, 10, 100}},
 Draw2D[
  {ComplexCartesianContour[f[z], {z, zmin, zmax}, Abs,
    Contours -> contourlist,
    ColorFunctionScaling -> False,
    ColorFunction -> (ContourColors[contourlist, 
       ColorData["TemperatureMap"]]),
    MaxRecursion -> 3,
    PlotRange -> {0, 100}]},
  Frame -> True, FrameLabel -> {Re, Im}, RotateLabel -> False,
  PlotLabel -> Row[{"Modulus of ", f[z]}],
  ImageSize -> 250]
 ]  

In the second graphic we use only the contour lines from the previous
graphic and place these on top of a domain coloring graphic that shows the
argument of the function. The argument varies from -\[Pi] (yellow) to \[Pi]
(brown). As an extra detail, the poles are marked with red points and the
zeros with blue points. Again the contour lines have tool tips because they
actually are from a contour plot.

poles = z /. Solve[1 + z + z^2 == 0];
zeros = z /. Solve[1 + z + z^2 + z^3 == 0];

With[
 {f = Function[z, (1 + z + z^2 + z^3)/(1 + z + z^2)],
  zmin = -1.5 (1.25 + I),
  zmax = (.8 + 1.5 I),
  contourlist = {0, 0.1, .3, .5, .7, .9, 1, 1.4, 2, 3, 5, 10, 100},
  colorfunction = ArgColor[Yellow, Brown, Black, White][]},
 Draw2D[
  {DomainColoring[f[z], {z, zmin, zmax}, colorfunction, 
    PlotPoints -> 100],
   ComplexCartesianContour[f[z], {z, zmin, zmax}, Abs,
    Contours -> contourlist,
    ContourStyle -> GrayLevel[.3],
    ContourShading -> False,
    MaxRecursion -> 3,
    PlotRange -> {0, 100}],
   ComplexCirclePoint[#, 3, Black, Red] & /@ poles,
   ComplexCirclePoint[#, 3, Black, Blue] & /@ zeros},
  Frame -> True, FrameLabel -> {Re, Im}, RotateLabel -> False,
  PlotLabel -> Row[{f[z]}],
  ImageSize -> 250]
 ] 


David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/   



From: fd [mailto:fdimer at gmail.com] 


All

I've used the DataRange option and it worked quite well. A bit of a
downside DataRange is not listed in the options of ArrayPlot.

Below is the code with an example of what I'm trying to do. Please let
me know if any of you would have a neater way of doing it. Many thanks
for the help.


a = ArrayPlot[
  Table[With[{z = x + I y},
    With[{w = (1 + z + z^2 + z^3)/(1 + z + z^2)}, Abs[w]]], {y, -1, 1,
     0.1}, {x, -1, 1, 0.1}], ColorFunction -> "TemperatureMap",
  DataRange -> {{-1, 1}, {-1, 1}}]


b = Graphics[Arrow[{{0, 0}, {1, 1}}]]



Show[b, Graphics[{Opacity[0.5], First@a}]]









On Apr 16, 7:53 pm, Patrick Scheibe <psche... at trm.uni-leipzig.de>
wrote:
> Hi,
>
> use DataRange to tell Mathematica about the rectangle where your
> ArrayPlot is in
>
> img = Import["http://sipi.usc.edu/database/misc/5.1.12.tiff";];
> Show[{
>   ArrayPlot[img[[1]], DataRange -> {{0, 2 Pi}, {-1, 1}},
>    ColorFunction -> GrayLevel],
>   Plot[Sin[x], {x, 0, 2 Pi}]
>   }]
>
> and you can overlay different plots.
>
> Cheers
> Patrick
>
>
>
> On Wed, 2010-04-14 at 23:13 -0400, fd wrote:
> > All
>
> > This seems a simple problem I not finding an easy solution.
>
> > I have a plot obtained from an ArrayPlot, for which the coordinates
> > are the indexes of the matrix being plotted; I want to overlay to this
> > plot some other plot, say, from DensityPlot. I have to tell
> > Mathematica that the bottom left corner of the ArrayPlot is {xi,yi}
> > and the upper right is {xf,yf}.
>
> > It would be nice as well to know how you could do this with a raster
> > image in general.
>
> > I was trying to use ListDensityPlot, but for the specific problem I
> > dealing with it is excruciatingly slow.
>
> > I'm also working to re-scale the FrameTicks by defining a new
> > ArrayPlot function, with limited success. Below the code I'm working
> > on.
>
> > Would anyone have an idea about this? Thanks in advance for any help.
> > Felipe
>
> > arrayPlotScale[array_List, {xmin_, xmax_}, {ymin_, ymax_}] :=
> >  Module[{deltas =
> >     Reverse[{ymax - ymin, xmax - xmin}/Dimensions[array]],
> >    n = Dimensions[array] // Reverse},
> >   ArrayPlot[array,
> >    FrameTicks ->
> >     Reverse[{Table[{i, xmin + i deltas[[1]] }, {i, 0, n[[1]], 20}],
> >       Table[{n[[2]] - i, ymin + i deltas[[2]]}, {i, 0, n[[2]],
> > 10}]}]]]
>
> > test = Table[i j, {i, 1, 100}, {j, 100, 1, -1}];
>
> > arrayPlotScale[test, {0, 16}, {0, 100}]





  • Prev by Date: Re: Nest and Fold don't respect HoldFirst?
  • Next by Date: Re: Where is the code for DistanceMatrix?
  • Previous by thread: Re: ArrayPlot coordinates scaling for overlays
  • Next by thread: BIOKMOD 5.0, a Mathematica tool for biokinetic modeling, fitting and