MathGroup Archive 2007

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

Search the Archive

Coordinate problems with Inset (and a bug)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg80578] Coordinate problems with Inset (and a bug)
  • From: thomas <thomas.muench at gmail.com>
  • Date: Sun, 26 Aug 2007 03:12:04 -0400 (EDT)

Hello, group,

**Part 1 of post **
Here is a problem I used to have with Mathematica 5.2 and the
Rectangle[coord,graphics] function to draw insets in a graphics. This
syntax is not working anymore in Mathematica 6, it has been replaced by Inset,
which has much more powerful placement capabilities. Nevertheless, I
still cannot do what I want.

So, here we go: I plot data, using ListLinePlot, ususally with Frame-
>True, Background->Gray, which represents the timecourse of
experimental biological data. At certain timepoints something happens
in the experiment, e.g. I show a light for 1 second. I would like to
indicate this event in the plot by plotting a white rectangle under
the data trace during the appropriate time (as a Prolog).

The problem is: The x-coordinates of the rectangle are absolute
coordinates (the time when the light goes on and off), while the y-
coordinates should span the whole plot, or the bottom 1/5th of the
plot, and are therefor relative, or scaled, coordinates. I cannot
figure out how to combine absolute coordinates in one dimension with
Scaled[] coordinates in the other dimension.

I know that I can get around this problem by using one of two tricks:
either  pre-computing the range of my data, and using absolute y-
coordinates (min and max of the data). Alternatively I can use
standard absolute y-coordinates that go way beyond the range of my
data, then only the part within the plotregion is shown, and it LOOKS
the way I want (it just seems like less than elegant solution).

**Part 2 of post**
Now to an apparent bug in Inset:

data=Range[20]/2;
rect=Graphics[Rectangle[]];

(* This works fine: *)
ListLinePlot[data, Frame -> True,
 Prolog -> Inset[rect, {2, 5}, {0, 0}, {2, 2}]]

Notice that a rectangle of size 2x2 is drawn, with its left bottom
edge ({0,0}) placed at position {2,5} in the plot.

According to the help file of Inset:
"y coordinates can be numbers, Automatic or Top, Center, Bottom,
Baseline or Axis."

The y-coordinate "5" is roughly in center of the plot, so I thought
the following should work and produce roughly the same result (but it
doesn't):

(* Here, no rectangle is drawn: *)
ListLinePlot[data, Frame -> True,
 Prolog -> Inset[rect, {2, Center}, {0, 0}, {2, 2}]]

The reason is that now, for some reason, Inset interprets the x-
coordinate as a relative (scaled) coordinate, so the rectangle
vanishes off to the right. In order to see the rectangle, the x-
coordinate has to be a fraction now. So, this brings back the
rectangle:

ListLinePlot[data, Frame -> True,
 Prolog -> Inset[rect, {.15, Center}, {0, 0}, {2, 2}]]

Is this a bug or a feature?????

thomas



  • Prev by Date: Re: Solving Nonlinear Equations
  • Next by Date: Re: Re: Intensive numerical calculations
  • Previous by thread: Re: Drawing tick labels without ticks
  • Next by thread: Bad imports of data files -- extra empty lists showing up?