MathGroup Archive 1999

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

Search the Archive

FW: Re: Plot & BoldPlot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg17123] FW: [mg17067] Re: Plot & BoldPlot
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Sat, 17 Apr 1999 03:35:14 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Bernd Brandt wrote:
 
---------------------------
The example code of Allan and Ted work fine. Thanks Allan and Ted!!
 
Unfortunately Mathematica print a decimal point (".") after the integer tick
labels.  1 becomes 1. 2 becomes 2. etc (already in FullOptions[gr, Ticks]).
 
<snip>
To prevent the printing of the decimal points after integer values I
changed "lab" in the code below into:
 
If[MatchQ[Rationalize[lab], Rational[_,_]], lab, Rationalize[lab] ]
 
(Seems strange to me having to do this.)
Below the code of Ted with changed including the above mentioned change.
 
 
===============================================
enlargeTicks[grObj_Graphics]:=
Module[{fulopts, tcklst},
  fulopts = FullOptions[grObj];
  tcklst = Ticks/.fulopts /.
    {loc_,lab_,len:{_,_},{a___,AbsoluteThickness[_],b___}}:>
      {loc, If[MatchQ[Rationalize[lab], Rational[_,_]], lab ,
       Rationalize[lab] ],
       1.5*len,{a,AbsoluteThickness[2],c}};
  grObj/.Graphics[prims_,(opts__)?OptionQ]:>
    Graphics[prims,Ticks->tcklst,opts]
]

BoldPlot[f_,PlotRange_,opts___?OptionQ]:=
Module[{gr,df},
  df=DisplayFunction/.Flatten[{opts,Options[Plot]}];
  gr=Plot[f,PlotRange,
    DisplayFunction->Identity, opts,
    PlotStyle->{AbsoluteThickness[2]},
    AxesStyle->{AbsoluteThickness[2]},
    TextStyle->{FontWeight->"Bold"}
  ];
  Show[enlargeTicks[gr],DisplayFunction->df]
]

gr=BoldPlot[Sin[x],{x,0,4 Pi}];


===========================
Bernd,

I have no idea why FullOptions wants to change Integer labels to Real
labels.
The line of code you added was:

If[MatchQ[Rationalize[lab], Rational[_,_]], lab, Rationalize[lab] ]

In any plot there aren't going to be lots of numbers that the expression
above is used on, so we are splitting hairs if we worry about how fast the
code above works.  However, you might come across other applications where
something like this will be used many times.  Below I consider the timing of
this code. 

--------------------------
Rational numbers have the head (Rational).  So the following will work and
should be a bit faster.

If[MatchQ[Rationalize[lab], _Rational], lab, Rationalize[lab] ]

--------------------------
Much better:
Version 3.0 has an IntegerPart function that's much faster than Rationalize.
Consider the timing tests below.

In[1]:=
f1=If[MatchQ[Rationalize[#],Rational[_,_]],#,Rationalize[#]]&;

In[2]:=
f2=If[IntegerPart[#]==#,IntegerPart[#],#]&;

In[3]:=
lst1=Table[5*Random[],{300}];

In[4]:=
f1/@lst1;//Timing
Out[4]=
{5.33 Second,Null}


Below (f2) is mapped over a much longer list in less time.

In[5]:=
lst2=Table[5 Random[],{10^4}];

In[6]:=
f2/@lst2;//Timing
Out[6]=
{4.67 Second,Null}

------------
For what it's worth the best line of code I can come up with is:
 
If[IntegerPart[lab]==lab, IntegerPart[lab], lab]
 
 
Regards,
Ted Ersek
 


  • Prev by Date: Display (was: psfix)
  • Next by Date: Re msg16940 Simplifying expressions
  • Previous by thread: Re: Plot & BoldPlot
  • Next by thread: How can draw Focus(Points)