       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 ...

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

In:= data = Table[Random[Integer,{1,10}], {10}, {2}]
Out= {{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:= ListPlot[data]
Out= -Graphics-

This makes the points red and big:

In:= ListPlot[data,
PlotStyle -> {RGBColor[1,0,0], PointSize[.025]}]
Out= -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:= circles={x_,y_} :> {RGBColor[0,1,0], Circle[{x,y},1]};

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

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

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

In:= Show[Graphics[data /. crosses],
AspectRatio->Automatic, Axes->Automatic]
Out= -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:= triangles = {x_,y_} :> {RGBColor[1,0,0],
Polygon[{{x-.5,y-Sqrt/4}, {x+.5,y-Sqrt/4},
{x,y+Sqrt/4}}]};

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

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

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

This function will color the triangles red by default.

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

You can explicitly color them blue, say:

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

Hope this helps.

Paul R. Wellin