MathGroup Archive 1997

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

Search the Archive

Re: Mathematica 2 problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg5790] Re: Mathematica 2 problem
  • From: "Paul R. Wellin" <wellin>
  • Date: Sat, 18 Jan 1997 14:58:41 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

At 02:17 PM 01/16/97 -0600, Marc Hainke wrote:
> generally when I create a graphic, the data points which
> are drawn by "ListPlot[data]" are shown as small filled
> circles.
> 
> I would like to know if it is possible to plot those points
> as boxes or triangles or crosses ...
> Could you please help me to solve this problem?

Sure. First, let's create a dataset to work with:

In[1]:= data = Table[Random[Integer,{1,10}], {10}, {2}]
Out[1]= {{9,7},{1,5},{7,8},{3,9},{8,2},{9,6},
         {2,10},{4,4},{8,10},{1,1}}


and then plot the data using defaults:

In[2]:= ListPlot[data]
Out[2]= -Graphics-


This makes the points red and big:

In[3]:= ListPlot[data,
           PlotStyle -> {RGBColor[1,0,0], PointSize[.025]}]
Out[3]= -Graphics-


Now, to get more involved shapes, you have to get away from ListPlot,
which limits you to plotting data as points. 

This is what you would do to convert the data points to green
circles centered on the point:

In[4]:= circles={x_,y_} :> {RGBColor[0,1,0], Circle[{x,y},1]};

In[5]:= Show[Graphics[data /. circles],
	     AspectRatio->Automatic, Axes->Automatic]
Out[5]= -Graphics-


Hopefully, this gives you the idea. Transform each data point
into the graphical object that you want. Here are the crosses:

In[6]:= crosses={x_,y_} :>
           {Line[{{x-.5,y}, {x+.5,y}}], Line[{{x,y-.5}, {x,y+.5}}]};

In[7]:= Show[Graphics[data /. crosses],
	    AspectRatio->Automatic, Axes->Automatic]
Out[7]= -Graphics-

I think you can see how to adjust these to make them thicker,
color them, make them larger or smaller, or turn 45 degrees if desired.

This gives you red triangles centered (need to do a bit of geometry and
algebra here) on each data point:

In[8]:= triangles = {x_,y_} :> {RGBColor[1,0,0],
      Polygon[{{x-.5,y-Sqrt[3]/4}, {x+.5,y-Sqrt[3]/4},
               {x,y+Sqrt[3]/4}}]};

In[9]:= Show[Graphics[data /. triangles],
	      AspectRatio -> Automatic, Axes -> Automatic]
Out[9]= -Graphics-


Here is a function you can use directly with your data sets (2D):

In[10]:= TriangleData[data_,color_:RGBColor[1,0,0],opts___]:= 
Module[{triangles},
   triangles = {x_,y_}:>{color,
      Polygon[{{x-.5,y-Sqrt[3]/4}, {x+.5,y-Sqrt[3]/4},
               {x,y+Sqrt[3]/4}}]};
   Show[Graphics[data /. triangles],
       opts, AspectRatio -> Automatic, Axes -> Automatic]]


This function will color the triangles red by default.

In[11]:= TriangleData[data]
Out[11]= -Graphics-

You can explicitly color them blue, say:

In[12]:= TriangleData[data, RGBColor[0,0,1]]
Out[12]= -Graphics-


Hope this helps.

Paul R. Wellin
Academic and Business Liaison
Wolfram Research, Inc.
wellin at wolfram.com


  • Prev by Date: special ColorFunction
  • Next by Date: Re: inert wrapping function
  • Previous by thread: special ColorFunction
  • Next by thread: Plots with mathematica