MathGroup Archive 2003

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

Search the Archive

Re: How do I make graphs of (easy) functions like those in textbooks?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg40447] Re: [mg40411] How do I make graphs of (easy) functions like those in textbooks?
  • From: Dr Bob <majort at cox-internet.com>
  • Date: Sat, 5 Apr 2003 04:02:15 -0500 (EST)
  • References: <200304040625.BAA06134@smc.vnet.net>
  • Reply-to: majort at cox-internet.com
  • Sender: owner-wri-mathgroup at wolfram.com

I used David Park's drawing package for this, which you can get at

http://home.earthlink.net/~djmp/

First, load the package.

Needs["DrawGraphics`DrawingMaster`"]

Here's a routine for building the graph paper gridlines.

gridLines[f_, xSpan : {_Integer | _Real, _Integer | _Real}] := 
Block[{ySpan, xGrid, yGrid, xGridFine, yGridFine, xGranularity,
   yGranularity},
    xGranularity = Round[xSpan.{-1, 1}/20];
    xGridFine = Range[Sequence @@ Inner[#1@#2 &, {Floor, Ceiling},
       xSpan, List], xGranularity];
    xGrid = Select[xGridFine, Mod[#, 5xGranularity] == 0 &];
    ySpan = {Min@#, Max@#} &[f /@ Join[xGridFine, xSpan]];
    yGranularity = Round[ySpan.{-1, 1}/20];
    yGridFine = Range[Sequence @@ Inner[#1@#2 &, {Ceiling,
             Floor}, ySpan, List], yGranularity];
    yGrid = Select[yGridFine, Mod[#, 5yGranularity] == 0 &];
    {Join[{#, {Blue}} & /@ xGrid, {#, {PowderBlue}} & /@ xGridFine], 
Join[{#, {Blue}} & /@ yGrid, {#, {PowderBlue}} & /@ yGridFine]}
    ]

Here's a routine for the plot.  It supplies some options, but also allows 
them to be overridden or supplemented.  It also allows graphics to be 
inserted along with the main function plot.

niceDraw[f_, graphicsPrimitives___,
    xSpan : {_Integer | _Real, _Integer | _Real}, opts___] :=
    Draw2D[{Draw[f@x,
            Evaluate@{x, Sequence @@ span}],
            graphicsPrimitives},
              opts,
              GridLines -> gridLines[f, span],
              PlotRange -> All, Frame -> True, Axes -> True, AspectRatio -> 
1,
              ImageSize -> 400,
              AxesStyle -> {Black, Thickness[0.005]},
              FrameLabel -> {x, y}, RotateLabel -> False];

Here's an example:

f[x_] := (x - 3)^2 - 1
niceDraw[f, AbsolutePointSize[5],
  Point /@ {{0, 8}, {2, 0}, {3, -1}, {4, 0}, {6, 8}}, {-5, 15},
  AspectRatio -> 0.7];

Bobby

On Fri, 4 Apr 2003 01:25:49 -0500 (EST), cdj <a_cjones at hotmail.com> wrote:

> Hi,
>
> I'm sure that questions like this have been asked/answered before, but
> I'm not sure what keywords to search on to find them... some obvious
> candidates didn't get me anywhere...
>
> Take, for example, f(x)= (x-3)^2 - 1
>
> I'd greatly appreciate seeing the Mathematica code that does the
> following:
>
> (a) Plots the parabola itself (duh).
> (b) Does so on a a gridded piece of "graph paper", with the axes
> substantially darker than the rest of the grid.
> (c) Both x and y axes are numbered at the units: 0, +-1, ..., +-10.
> The numbers should be to the left of the y axis, and below the x axis.
> The origin doesn't have to be labelled, if it's ugly, or too hard.
> (d) The y axis is labelled "y" at the top of the graph, x axis is
> labelled "x" on the right.
> (e) Puts little arrows on the 4 tips of the axes (signifying that they
> continue arbitrarily far).
> (f) The following points are explicitly represented with
> reasonable-sized dots: (0,8), (2, 0), (3,-1), (4,0), and (6,8).
> (g) It would be nice, but not essential, if the tips of the parabola
> itself had little arrows (again signifying that it continues upward
> with increasing abs(x) values.
>
> Sorry for all the conditions - just trying to be somewhat precise
> about what I meant by graphs "like those in textbooks". Once I get the
> code for this, I'm sure I can modify it to other similar tasks...
>
> Can all these desiderata be obtained in *one* Mathematica graph? Or is
> there another graphics/graphing program that is better-suited to such
> tasks?
>
> Thanks a bunch for any help,
>
> cdj
>
>



-- 
majort at cox-internet.com
Bobby R. Treat



  • Prev by Date: Re: Parallel Kit Question: ParallelDot is much more slow than Dot
  • Next by Date: Re: How do I make graphs of (easy) functions like those in textbooks?
  • Previous by thread: How do I make graphs of (easy) functions like those in textbooks?
  • Next by thread: Re: How do I make graphs of (easy) functions like those in textbooks?