Re: very simple plot format
- To: mathgroup at smc.vnet.net
- Subject: [mg33900] Re: [mg33891] very simple plot format
- From: BobHanlon at aol.com
- Date: Mon, 22 Apr 2002 00:57:33 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 4/21/02 6:51:06 AM, res04oor at gte.net 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. > Needs["Graphics`Colors`"]; 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, AspectRatio->Automatic, FrameTicks-> { Join[Table[{k,k}, {k,myRound[xmin,gridMajor], myRound[xmax,gridMajor],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], myRound[xmax,gridMinor]}], Table[k, {k,Round[ymin],Round[ymax]}]} /. x_?(IntegerQ[#/gridMajor]&) :> {x,{Red,AbsoluteThickness[.5]}}), PlotRange -> {ymin,ymax}, ImageSize->300]; Bob Hanlon Chantilly, VA USA