# Re: labeling a plot in a viewport

```Hello Hein,
Good questions!

- How do I specify label coordinates relative to the axes of the plot
if I don't know the data along the axis? It's a general script, so I
cannot assume that the left bottom corner is always 120E,30S.

You can get information about the axes, among other things, from
symbols that are defined by Ferret when you make a plot.  After
plotting, say:
yes? SHOW SYMBOL
and you'll see a long list of the symbols that have been defined.
You can use ppl\$xmin, ppl\$xmax, ppl\$ymin, ppl\$ymax to
generate label positions.  This works whether you're in a
viewport or not.  So for example to put a label near the top
inside the plot:

yes? set view ul
yes? show symbol

yes? let xmid = ( (\$ppl\$xmax) - (\$ppl\$xmin) )/2
yes? let ytop = 0.9* ((\$ppl\$ymax) )
yes? label/user `xmid`, `ytop`, -1, 0, 0.15, "my label"

( Note the definition of ytop might give unexpected results
if the value ppl\$ymax were negative.  To be completely
general you would want to be more careful!)

- I draw the title of the plot in a 13th viewport at the bottom of the
page, specified with define viewport /axes. I found out that
relative coordinates (0.5,0.5 for a centered label) only work after
you plot something in that viewport. How do I 'initialize' a
viewport so that these relative coordinates work, without actually
plotting something in it?

There needs to be some kind of plot in order for Ferret to know
the scaling of space in the veiwport, and be able to position a
label.  The plot symbols need to be set, as we saw above.  You
could do a plot like this, shaded all in white, and then put the label
on.  The label position is relative to the i=1:2 and j=1:2 axes
which are defined even though they aren't plotted on the shade plot.

yes? set view ur
yes? label/nouser 1.5,1.5,0, 0, 0.15 "centered label only"

Or, here is a way of adding a box anywhere on your page which
contains a label. I'll just use the pre-defined viewports for an
example, and I will fill the box with red to make it obvious.
You could do a box of any color, anywhere on the page.
The viewport definition is relative to the entire page, and it can
overlap other viewports.  The /AXES qualifier on the DEFINE
VIEWPORT command indicates that the viewport definition
is the location of the axes.  This way we can fill in the entire
plot with a color, and use the coordinates of the axes to
position the label.  The /TEXT qualifier makes the text size in
the viewport the same as it would be in the full window;
which makes it easier to control the size of the label.

yes? set view upper; shade/l=2 sst
yes? set view lower; shade/l=4 sst

yes? define view/xlim=0.4:0.6/ylim=0.45:0.5/axes/text=1 little_box
yes? set view little_box
yes? label/user 1.5 1.1 0 0, 0.15 @crtext in box

Hein Zelle wrote:

> Dear Ferret users and developers,
>
> As a followup question on the previous one, I'd like to know how to
> use 'user' and 'global' coordinates when labelling a plot that is in a
> viewport which takes up only part of the page. Here's what I want to
> do: I have divided my page into 12 viewports, one for each month, just
> like the landscape3x2 script. (If anyone is interested, I now have a
> portrait2x6 script). I make a contour plot in the first viewport of,
> say, the january climatology.
>
> So far so good, but the title of the plot doesn't really fit in such a
> small viewport so I leave it off. Instead, I want to plot a label with
> 'January' within the area of the plot. Ideally, I want this label to
> appear within a white box, so it doesn't run through the contour
> lines. The questions I ran into:
>
> - How do I specify label coordinates relative to the axes of the plot
>   if I don't know the data along the axis? It's a general script, so I
>   cannot assume that the left bottom corner is always 120E,30S.
>
> - How can I make a white box around a label? I was thinking of using a
>   very small 'label' viewport for this, but just as with the label I
>   don't know how to position this 'subviewport'.
>
> - I draw the title of the plot in a 13th viewport at the bottom of the
>   page, specified with define viewport /axes. I found out that
>   relative coordinates (0.5,0.5 for a centered label) only work after
>   you plot something in that viewport. How do I 'initialize' a
>   viewport so that these relative coordinates work, without actually
>   plotting something in it?
>
> I will attach the two scripts to this mail so you can check them
> out. 12month.jnl defines the viewports (the 'label' viewports are
> commented out), 12plot.jnl is a general script to plot 12 months of a
> climatology.
>
> I hope someone can help with this, the result already looks pretty
> good but could be perfected some more.
>
>      Hein Zelle
>
> >-----------------------------------------------------------------<
>     Hein Zelle
>     Dept. of Oceographic Research
>     KNMI, The Netherlands
>     work:        zelle@knmi.nl     http://www.knmi.nl/~zelle
>     private:     hein@icce.rug.nl http://www.icce.rug.nl/~hein
>     Phone:       +31 (0)30 2206704
> >-----------------------------------------------------------------<
> --------------------------------------------------------------
>
>   ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>                  Name: 12plot.jnl
>    12plot.jnl    Type: Plain Text (text/plain)
>              Encoding: 7BIT
>
>                   Name: 12month.jnl
>    12month.jnl    Type: Plain Text (text/plain)
>               Encoding: 7BIT

--
Ansley Manke  Pacific Marine Environmental Laboratory  Seattle WA  (206)526-6246

```