MathGroup Archive 2008

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

Search the Archive

Equi-sized tick labels

  • To: mathgroup at smc.vnet.net
  • Subject: [mg85266] Equi-sized tick labels
  • From: Will Robertson <wspr81 at gmail.com>
  • Date: Tue, 5 Feb 2008 05:56:29 -0500 (EST)

Dear all,

When Mathematica creates tick marks in plots, it uses a ratio of the
plot size to calculate their length. Unfortunately, it treats
horizontal and vertical sizes separately so non-square plots will have
unequal tick marks in the two different directions. This can look
rather ugly, in my opinion.

Luckily, it's an easy problem to fix. Please find attached some code
to "normalise" the length of the ticks used in plots so that non-
square plots don't have uneven ticks horizontally and vertically. It
uses the CustomTicks package, whose author I shall contact about
rolling this functionality into his package.

Have fun,
Will

Here is the code. It may be modified and distributed freely under the
Apache Licence, v2.

<< "CustomTicks`"

ticksize := 0.02
smallticksize := 0.01
aspectratio := 0.8
padratio := 1.5

XTicks[a_, b_, opts___] := LinTicks[a, b,
  MajorTickLength -> {ticksize, 0},
  MinorTickLength -> {smallticksize, 0},
  opts
  ]
YTicks[a_, b_, opts___] := LinTicks[a, b,
  MajorTickLength -> {ticksize/aspectratio, 0},
  MinorTickLength -> {smallticksize/aspectratio, 0},
  opts
  ]

EmptyXTicks[a_, b_] := XTicks[a, b, ShowTickLabels -> False]
EmptyYTicks[a_, b_] := YTicks[a, b, ShowTickLabels -> False]

SetOptions[Plot, Frame -> True, AspectRatio -> aspectratio,
  FrameTicks -> {{XTicks, EmptyXTicks}, {YTicks, EmptyYTicks}},
  PlotRangePadding ->
   {Scaled[padratio*ticksize],
    Scaled[padratio*ticksize/aspectratio]}];
Plot[x, {x, 0, \[Pi]}]


  • Prev by Date: Plot function of a function of a variable
  • Next by Date: Re: <<ImageProcessing` error
  • Previous by thread: Re: Plot function of a function of a variable
  • Next by thread: Re: Equi-sized tick labels