MathGroup Archive 2002

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

Search the Archive

Re: very simple plot format

  • To: mathgroup at
  • Subject: [mg33900] Re: [mg33891] very simple plot format
  • From: BobHanlon at
  • Date: Mon, 22 Apr 2002 00:57:33 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

In a message dated 4/21/02 6:51:06 AM, res04oor at writes:

>My problem is getting gridlines and tick marks the way I want them.  I
>cannot find an explicit answer in the Mathematica book.  Consider the
>following simple plot:
>Plot[2 x - 4, {x,-10,10}]
>I want gridlines at every integer in the domain and the range, and tick
>marks at the fraction of integer, for example.  How can I expressly detrmine
>the placement of gridlines etc.


myRound[x_, incr_] := Round[x/incr]*incr;

xmin = -10; xmax = 10; 
ymin = -26; ymax = 17;
gridMajor = 5; gridMinor = 1;
tickIncr = 1/2;

Plot[2 x-4,{x,xmin,xmax},
    PlotStyle->{{Green, AbsoluteThickness[2]}},
    Frame->True, Axes->False,
    FrameTicks-> {
        Join[Table[{k,k}, {k,myRound[xmin,gridMajor],
          Table[{k,""}, {k,myRound[xmin, tickIncr],
              myRound[xmax, tickIncr], tickIncr}]],
        Join[Table[{k,k}, {k,myRound[ymin, gridMajor],
              myRound[ymax, gridMajor],gridMajor}],
          Table[{k,""}, {k,myRound[ymin, tickIncr],
              myRound[ymax, tickIncr], tickIncr}]]},
    GridLines-> ({
            Table[k, {k,myRound[xmin,gridMinor],
            Table[k, {k,Round[ymin],Round[ymax]}]} /.
          x_?(IntegerQ[#/gridMajor]&) :>
    PlotRange -> {ymin,ymax},

Bob Hanlon
Chantilly, VA  USA

  • Prev by Date: Re: Bug in Sum causes index variable to remain set?
  • Next by Date: RE: Re: Using NonlinearFit/Regress?
  • Previous by thread: very simple plot format
  • Next by thread: RE: very simple plot format