MathGroup Archive 2007

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

Search the Archive

Re: FrameTicks lengths

Kevin J. McCann wrote:

>Is there a way to make the tick marks on a Framed plot longer than the 
>default without explicitly specifying the length for each tick?
You can use AbsoluteOptions or FullAxes to get the automatic ticks, and 
then modify them. The only problem is that AbsoluteOptions and FullAxes 
do not fully support the new version 6 graphics primitives and options. 
Anyway, here is a function I've used to do this:

Options[LinearScale] = {"MinorTicks" -> True,
   "TickLength" -> 1, "TickExtent" -> "In",
   "TickLabels" -> True};

LinearScale[min_, max_, OptionsPattern[]] :=
Module[{minor, length, extent, labelpattern, ticks},
    {minor, length, extent} = OptionValue[{"MinorTicks", "TickLength", 
    extent = Switch[extent, "Out", Reverse, "Both", Reverse[#] + # &, _, 
    ticks = First[Ticks /.
        FullAxes[Graphics[{}, Ticks -> Automatic, PlotRange -> {{min, 
max}, Automatic}]]
    If[minor, labelpattern = _, labelpattern = Except[""]];
        {x_, y : labelpattern, z_, w_} :>
            {x, If[OptionValue["TickLabels"], y, ""], length extent[z], w}

And here is an example that uses LinearScale:

Plot[Sin[x], {x, 0, 2 Pi}, Frame -> True,
 FrameTicks -> {LinearScale[0, 2 Pi, "TickLength" -> 3],
   LinearScale[-1, 1, "MinorTicks" -> False],
   LinearScale[0, 2 Pi, "TickLabels" -> False],
   LinearScale[-1, 1, "TickExtent" -> "Out"]},
 PlotRangePadding -> None]

Basically, the above FrameTicks option specifies that the bottom frame 
gets ticks that are 3 times as long, the left frame has no minor ticks, 
the top frame has no labels, and the right frame has the ticks sticking 
outside the frame. If you do not know the plot range before hand, then 
the process becomes a little more involved.

Carl Woll
Wolfram Research

  • Prev by Date: Re: How to make delayed functions from text info
  • Next by Date: Re: How to invert a function
  • Previous by thread: FrameTicks lengths
  • Next by thread: FactorInteger slow in V6.0 vs V5.2