Re: plotting multiple polygons
- To: mathgroup at smc.vnet.net
- Subject: [mg29184] Re: plotting multiple polygons
- From: Tom Burton <tburton at cts.com>
- Date: Sat, 2 Jun 2001 05:54:38 -0400 (EDT)
- Organization: Brahea Consulting
- References: <9f7k2s$gup$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, Consider a file temp.txt: 1 1 2 1 1 2 1 1 3 1 4 1 3 2 3 1 The first issue is to get Mathematica to include the blank lines in the processed input. I could not quickly get Mathematica to do this with Number, so I used Word instead and them converted the words to expressions: In[27]:= data1 = Map[ToExpression, ReadList["temp.txt", Word, NullRecords -> True, RecordLists -> True], {2}] {{1, 1}, {2, 1}, {1, 2}, {1, 1}, {}, {3, 1}, {4, 1}, {3, 2}, {3, 1}, {}} The next thing to do is to split the list into sublists, breaking at the empty lists: In[28]:= data2 = Split[data1, #1 != {} & ] {{{1, 1}, {2, 1}, {1, 2}, {1, 1}, {}}, {{3, 1}, {4, 1}, {3, 2}, {3, 1}, {}}} In[29]:= data3 = (DeleteCases[#1, {}] & ) /@ data2 {{{1, 1}, {2, 1}, {1, 2}, {1, 1}}, {{3, 1}, {4, 1}, {3, 2}, {3, 1}}} The Polygon[__] pattern does not include the repeated first point, so if you want to use Polygon, drop the first (or last) point from each sublist: In[30]:= data4 = Rest/@data3 {{{2, 1}, {1, 2}, {1, 1}}, {{4, 1}, {3, 2}, {3, 1}}} Then to show filled polygons: In[31]:= Show[Graphics[Polygon /@ data4]]; To show unfilled polygons, you can use the low-level form In[32]:= Show[Graphics[Line /@ data3]]; The easiest high-level command to use is probably MultipleListPlot In[33]:= Needs["Graphics`MultipleListPlot`"] I needed the PlotStyle Command to prevent MultipleListPlot from assigning various styles to the various polygons: In[34]:= MultipleListPlot[Sequence @@ data3, PlotJoined -> True, PlotStyle -> Dashing[{}]]; Tom Burton ------ On Fri, 1 Jun 2001 08:34:36 +0000 (UTC), in comp.soft-sys.math.mathematica you wrote: >Hi again! > >I have a set of points in ASCII file as follows: > >x11 y11 >x12 y12 >.... >x1n1 y1n1 >x11 y11 > >x21 y21 >x22 y22 >.... >x2n2 y2n2 >x21 y21 > >x31 y31 >x32 y32 >.... >x3n3 y3n3 >x31 y31 > >.... > >Basically, there are multiple (and many many) groups of consecutive >lines of x and y coordinates of points, each group representing a >polygon and each group is separated by an empty line from other >groups. > >I need to make one plot that shows all the polygons, unconnected one >another. > >If I do the following, I would get a plot that shows all the polygons >connected one another. > >In[1]:= polygons = ReadList["asciiFile",Table[Number,{2}]]; >In[2]:= ListPlot[polygons, PlotJoined->True]; > >Any simple way to draw standalone polygons in one plot? > >Thanks, > >Xiangdong Liu > Tom