Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Position of tick labels in 2D plots

1,016 views
Skip to first unread message

D.J. Wischik

unread,
Jan 13, 2003, 4:14:34 AM1/13/03
to
I have a 2D plot, whose PlotRange is {{0,10},{-5,0}}. Since all the action
takes place in the lower right hand quadrant, I would like the tick
marks and the numbers on the axes to be positioned outside this quadrant:
thus
2 4 6 8
| | | |
----------------
|
-2 -|
|
-4 -|
|

I am using the Ticks option, to ensure that the tick marks are drawn
above the x-axis and to the left of the y-axis. The tick labels for
the y-axis are automatically drawn to the left of the y-axis, but
those for the x-axis default to below the x-axis.

How can I change this behaviour?

Damon Wischik.

Jens-Peer Kuska

unread,
Jan 14, 2003, 6:11:24 AM1/14/03
to
Hi,

Frame->True and FrameTicks-> _

and your ticks will never overlap the drawing area and
it looks better because it guide the eyes.

Regards

Allan Hayes

unread,
Jan 14, 2003, 6:14:32 AM1/14/03
to
Damon,

I had to use frame and frameticks to get the x-axis labels above the axis.

<< "Graphics`Graphics`"(*to get UnitScale*)

xxticks = (Append[#1,{0,0.02}]&)/@UnitScale[2,8,2];
yyticks = (Append[#1,{0,0.02}]&)/@UnitScale[-4,-1,1];

Show[Graphics[{}, PlotRange -> {{0, 10}, {-5, 0}}],
Frame -> {False, True, True, False}, Axes -> False,
FrameTicks -> {{}, yyticks, xxticks, {}}]

Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
h...@haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565


"D.J. Wischik" <djw...@cus.cam.ac.uk> wrote in message
news:avu01q$dcf$1...@smc.vnet.net...

Wolf, Hartmut

unread,
Jan 14, 2003, 6:16:36 AM1/14/03
to

>-----Original Message-----
>From: djw...@cus.cam.ac.uk [mailto:djw...@cus.cam.ac.uk]
>Sent: Monday, January 13, 2003 10:12 AM
>To: math...@smc.vnet.net
>Subject: Position of tick labels in 2D plots
>
>
>I have a 2D plot, whose PlotRange is {{0,10},{-5,0}}. Since
>all the action
>takes place in the lower right hand quadrant, I would like the tick
>marks and the numbers on the axes to be positioned outside
>this quadrant:
>thus
> 2 4 6 8
> | | | |
> ----------------
> |
> -2 -|
> |
> -4 -|
> |
>
>I am using the Ticks option, to ensure that the tick marks are drawn
>above the x-axis and to the left of the y-axis. The tick labels for
>the y-axis are automatically drawn to the left of the y-axis, but
>those for the x-axis default to below the x-axis.
>
>How can I change this behaviour?
>
>Damon Wischik.
>

Damon,

let's make up a sample

In[1]:= p[t_] := t^5 - 5t^3 + 4t

The easiest way is -- as it appears to me -- to use the Frame option

In[3]:= Plot[-1/(1 + p[x - 4]^2), {x, 0, 8},
Frame -> True,
FrameTicks -> {None, True, True, None}]

If for some reason you don't like that, a custom tick function may affect
the length, direction etc. of the tick marks, yet not the positioning of the
tick labels. This simply is, because the Tick specification doesn't allow
it, in other words: the algorithm for positioning the labels is buried into
Show. (This certainly has the advantage of allowing to use a universal
TickFunction for each axis or frame in most cases.)

Here we use a tick function e.g. from TWJ's package which had been available
at MathSource item 0208-976 until recently (I didn't find it in the revised
WRI resource library, that is) to first make the ticks point to where we
(sorry me) liked to:

In[4]:= << ExtendGraphics`Ticks`
In[5]:= tf = TickFunction[#1, #2,
MajorLength -> {0, 0.00625},
MinorLength -> {0, 0.003125}] &;

In[6]:= Plot[-1/(1 + p[x - 4]^2), {x, 0, 8},
Ticks -> {tf, TickFunction}]

Therefore we have to get at the FullGraphics, and manipulate the Text
positions; e.g. this will do for the example given:

In[7]:= g = FullGraphics[%]

In[8]:=
Show[g /. Text[label_, {xpos_, ypos_}, {0., 1.}] :>
Text[label, {xpos, 0}, {0, -1}], PlotRegion -> {{0, 1.1}, {0, .97}},
Background -> Hue[.3, .2, 1]]

You finally have to make adjustments for the PlotRegion, as to see all from
the labels.

--
Hartmut Wolf
________
P.S. If you prefer the tick marks to point to the outside, as you indicated,
just do

In[17]:=
g = FullGraphics[
Plot[-1/(1 + p[x - 4]^2), {x, 0, 8}, Ticks -> {TickFunction, tf},
DisplayFunction -> Identity]]

In[18]:=
Show[g /. Text[label_, {xpos_, ypos_}, {0., 1.}] :>
Text[label, {xpos, 0.01}, {0, -1}], PlotRegion -> {{0, 1.1}, {0,
.97}},
Background -> Hue[.3, .2, 1]]


David Park

unread,
Jan 14, 2003, 6:19:43 AM1/14/03
to
Damon,

Use a Frame and suppress two of the sides. Here is an example for a negative
sine wave. When the ticks are put along the top of the frame the labels are
automatically above.

xticks = Join[Table[{x, x, {0, 0.00625}}, {x, 0, 3, 0.5}],
Table[{x, "", {0, 0.00375}}, {x, 0, 3, 0.1}]];

yticks = Join[Table[{y, y, {0, 0.00625}}, {y, -1, 0, 0.2}],
Table[{y, "", {0, 0.00375}}, {y, -1, 0, 0.04}]];

Plot[-Sin[x], {x, 0, Pi},


Frame -> {False, True, True, False},

FrameTicks ->
{None,
yticks,
xticks,
None},
ImageSize -> 400
];

The DrawGraphics package at my web site has a CustomTicks function that
makes it a little easier to specify ticks and also to produce
transformations to the tick scales.

Needs["DrawGraphics`DrawingMaster`"]

xticks = CustomTicks[Identity, {0, 3.5, 0.5, 5}, CTTickSpecs -> {0,
0.00625},
CTUnLabTickSpecs -> {0, 0.00375}];

yticks = CustomTicks[Identity, {-1, 0, 0.2, 5}, CTTickSpecs -> {0, 0.00625},
CTUnLabTickSpecs -> {0, 0.00375}];

David Park
dj...@earthlink.net
http://home.earthlink.net/~djmp/

Kirk Reinholtz

unread,
Jan 14, 2003, 6:21:46 AM1/14/03
to
If you use Frames->True, you'll find that Mathematica won't put ticks down the
middle of your graph, and you can specify the ticks at each edge, via
FrameTicks: left, right, top, and bottom. Might do what you wish.
0 new messages