Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2013

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

Search the Archive

Re: Number Separator for Number Labels on Plot Axes

  • To: mathgroup at smc.vnet.net
  • Subject: [mg131977] Re: Number Separator for Number Labels on Plot Axes
  • From: Alexei Boulbitch <Alexei.Boulbitch at iee.lu>
  • Date: Fri, 8 Nov 2013 16:23:44 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net

Hello everyone,

Is there a way to format the numbers that appear on the axes of plots, for example, including number separators for thousands, as in 2,000, 3,400, etc., or including dollar signs, $5, $6, and so on? I tried using NumberForm on Ticks but that gave me an error.

Gregory


Hi, Gregory,

The answer to the first half of you question may be as follows:

Plot[150000*Sin[x], {x, 0, 2 \[Pi]},
 TicksStyle -> Directive[DigitBlock -> 3, NumberSeparator -> " ,"]]

Try it.

The answer to the second half is a bit more complex, since the sign of dollar is reserved in Mathematica. The workaround would be to put this sign in a string form. Like this, for example:

Plot[Sin[x], {x, 0, 2 \[Pi]},
 Ticks -> {Automatic, {{-1, "-$1"}, {-0.5, "-$0.5"}, {0.5,
     "$0.5"}, {1, "$1"}}}]

Or you can make the Ticks programmatically:

lst = Table[{i, "$" <> ToString[i]}, {i, -1, 1, 0.5}]

{{-1., "$-1."}, {-0.5, "$-0.5"}, {0., "$0."}, {0.5, "$0.5"}, {1.,
  "$1."}}

and then

Plot[Sin[x], {x, 0, 2 \[Pi]}, Ticks -> {Automatic, lst}]

Or, if you care for the simultaneous position of the minus and the dollar sign, try this:

lst1 = Table[{i,
   If[i < 0, "-$" <> ToString[Abs[i]], "$" <> ToString[i]]}, {i, -1,
   1, 0.5}]

{{-1., "-$1."}, {-0.5, "-$0.5"}, {0., "$0."}, {0.5, "$0.5"}, {1.,
  "$1."}}

Plot[Sin[x], {x, 0, 2 \[Pi]}, Ticks -> {Automatic, lst1}]

Have fun, Alexei


Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG

Office phone :  +352-2454-2566
Office fax:       +352-2454-3566
mobile phone:  +49 151 52 40 66 44

e-mail: alexei.boulbitch at iee.lu





  • Prev by Date: Re: Unit conversion of a list of quantities
  • Next by Date: Re: Manipulate semi-share
  • Previous by thread: Re: Number Separator for Number Labels on Plot Axes
  • Next by thread: Re: Exercise of Programming with Mathematica