RE: Position of tick labels in 2D plots
- To: mathgroup at smc.vnet.net
- Subject: [mg38810] RE: [mg38800] Position of tick labels in 2D plots
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Tue, 14 Jan 2003 06:10:42 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
>-----Original Message----- >From: djw1005 at cus.cam.ac.uk [mailto:djw1005 at cus.cam.ac.uk] To: mathgroup at smc.vnet.net >Sent: Monday, January 13, 2003 10:12 AM >To: mathgroup at smc.vnet.net >Subject: [mg38810] [mg38800] 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]]