MathGroup Archive 1998

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

Search the Archive

RE: graphics question




Tom wrote:
|
|Suppose I am using Mathematica to create test questions for my high
|school math students.  Here is a simple question. |
|Use the grid below to draw the graph of y = 2x - 4 |
|Now, I can create a really nice grid (using simple grid, available from
|Mathsource) and I can easily plot this graph to create the answer, but
|is there any way to create a "blank" set of gridlines that will be
|identical to the gridlines Mathematica will create for the plot? The
|idea would be to provide students with a grid to put their answer on,
|and have that match the output Mathematica will create. |
|I tried plotting the graph with a color of White, but for the
observant, |you can see where the invisible line crosses the gridlines!
(connect |the dots and you have the answer!)
|
|Plot[2x-4, {x, -5,5}, GridLines->Automatic] |
|Plot[2x-4, {x, -5,5}, GridLines->Automatic, PlotStyle->{GrayLevel[1]}]
|
|I would be looking for a solution that would work for more complicated
|functions to graph as well, this was just a simple illustration. |

I have good new and bad news.  The good news is that we can get what you
want.  The bad news is that you have to do a lot of work if you are 
particular about what the results look like.

The following does much of what you want with built-in features.

In[1]:=
grid=ListPlot[{{-6,-6},{6,6}},PlotStyle->PointSize[0.],
     GridLines->Automatic]

Out[1]=
 -Graphics deleted-

But I don't like the graphic above very much.  The grid lines go through
the  numbers, and the gridlines stick out on the edges.  In the lines
below I  change this into a graphic I like better.

If you want to control the nitty gritty details as I do below, I
recommend that you purchase "The Mathematica Graphics Guidebook" by
Cameron Smith and Nancy Blachman
__________________________________

FullGraphics gives all the lower level primitives used to make the
graphic  above.

In[2]:=
g1=FullGraphics[grid];

Note:  Evaluate   InputForm[g1]   to see g1 in all it's glory.

Now I need to find the expression used to make the numbers.

In[3]:=
Position[g1,Text]

Out[3]=
{{1,2,16,0},{1,2,18,0},{1,2,20,0},{1,2,22,0},{1,2,24,0},{1,2,26,0},
{1,2,47,0},{1,2,49,0},{1,2,51,0},{1,2,53,0},{1,2,55,0},{1,2,57,0}}


In[4]:=
g1[[1,2,18]]

Out[4]=
Text[-4,{-4.,-0.25484},{0.,1.}]


Next I find the expression used to make the grid.

In[5]:=
Position[g1,Line]

Out[5]=
 -Long Output deleted-


In[6]:=
g1[[1,2,76,3]]

Out[6]=
Line[{{0.,-6.3},{0.,6.3}}]


In[7]:=
g1[[1,2,45,3]]

Out[7]=
Line[{{-6.3,0.},{6.3,0.}}]


Now I know what expressions in (g1) need to be changed, and I can use 
replacement rules to change the grid lines and the numbers.

In[8]:=
g2=g1/.
{Text[str_,{x_,y_},{0.,1.}]->Text[str,{x,y},{0.,0.6}, 
Background->Automatic],
Text[str_,{x_,y_},{1.,0.}]->Text[str,{x,y},{1.,0.},
Background->Automatic],
Line[{{-6.3,y_},{6.3,y_}}]->Line[{{-6.,y},{6.,y}}],
Line[{{x_,-6.3},{x_,6.3}}]->Line[{{x,-6.},{x,6.}}]     }

Out[8]=
 -Graphics-


In[7]:=
Show[g2]

Out[7]=
 -Graphics deleted-

I like the graphic above much better.  If anyone knows know of an easier
way  to control details like I did above please let me know.

Ted Ersek




  • Prev by Date: Re: Solve for positive, real-valued solutions
  • Next by Date: Re: Solve for positive, real-valued solutions
  • Prev by thread: Re: graphics question
  • Next by thread: Re: graphics question