Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm a beginner with Mathematica, so this may seem like a simple question, though it's got me totally stumped. I'm trying to display several polygons and have the color of each polygon depend on the value in some other variable (stscds). My thinking is that I should do something like this:

Show[Graphics[Table[{RGBColor[stscds[[i]],0,0,0.2],EdgeForm[Black],poly[[i]]}, {i,1,300,1}]]]

poly contains all of the polygons. Or possibly this:

megapol = Table[{RGBColor[stscds[[i]],0,0,0.2],EdgeForm[Black],poly[[i]]}, {i,1,300,1}] Graphics[megapol]

It doesn't like that I'm trying to pull the color parameter out of stscds (this variable is full of values between 1 and zero). It says 'Ignoring invalid graphics directive RGBColor[0,01 1,0,0]. Any idea how I might approach this problem?

Edit: Output of stscds:

{("1")/100, ("1")/100, ("1")/100, ("1")/100, ("1")/100, ("1")/100, \ ("1")/100, ("1")/100, ("1")/100, ("2")/100, ("2")/100, ("2")/100, \ ("2")/100, ("2")/100, ("2")/100, ("3")/100, ("4")/100, ("4")/100, \ ("4")/100, ("4")/100, ("4")/100, ("4")/100,....

share|improve this question

closed as off-topic by Michael E2, bobthechemist, Sjoerd C. de Vries, Simon Woods, Ajasja Feb 23 at 12:02

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Michael E2, bobthechemist, Sjoerd C. de Vries, Simon Woods, Ajasja
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
How about including some sample of stscds contents? If the error actually has the format you posted, probably something whacked in the format, and you seem to be supplying too many arguments to RGBColor... –  rasher Feb 23 at 1:03
1  
You're dividing a string... turn the ("x")/... into x/... –  rasher Feb 23 at 1:09
    
Ah, you're right. stscds was full of strings, which I didn't realize. I used ToExpression to convert it to numerical. Thanks a million rasher. –  Mas Feb 23 at 1:21
add comment

1 Answer 1

I post this as motivation for experimenting to get desired result. I have made no effort to create convex polygons or avoiding intersections. My main aim is to illustrate some coloring options:

  1. Generate some polygons:

    pol = RandomReal[{0, 1}, {10, 5, 2}]
    
  2. Some coloring options:

Using ColorData

    Graphics@MapThread[{Opacity[0.5], ColorData["Rainbow"][#1], 
    Polygon@#2} &, {RandomReal[{0, 1}, 10], pol}]

enter image description here

Using RGBColor (random shades of Red)

    Graphics@MapThread[{Opacity[0.5], RGBColor[#1, 0, 0], 
    Polygon@#2} &, {RandomReal[{0, 1}, 10], pol}]

enter image description here

Using Hue

    Graphics@MapThread[{Opacity[0.5], Hue[#1], 
    Polygon@#2} &, {RandomReal[{0, 1}, 10], pol}]

enter image description here

There are a number of other approaches. I suggest looking at documentation and playing. I have merely used random coloring but the approch could be adapted to your user defined desired coloring after you choose a suitable color scheme.

A more specific example (with absolutely no political subtext in coloring):

 poly = CountryData[#, "SchematicPolygon"] & /@ {"UnitedStates", 
"Canada", "Mexico"};
 Graphics@MapThread[{#1, #2} &, {{Red, Blue, Yellow}, poly}]

enter image description here

Using OP stscds

stscds = {("1")/100, ("1")/100, ("1")/100, ("1")/100, ("1")/
    100, ("1")/100, ("1")/100, ("1")/100, ("1")/100, ("2")/100, ("2")/
    100, ("2")/100, ("2")/100, ("2")/100, ("2")/100, ("3")/100, ("4")/
    100, ("4")/100, ("4")/100, ("4")/100, ("4")/100, ("4")/100};
recode = MapAt[ToExpression, stscds, {All, 2}];
pg = Polygon /@ RandomReal[{0, 5}, {Length@recode, 3, 2}];
Graphics@MapThread[{Opacity[0.5], 
    RGBColor[#1, 0, 0.2], #2} &, {recode, pg}]

enter image description here

share|improve this answer
    
Thanks, some of those color function will be usefull –  Mas Feb 23 at 3:01
    
@Mas just thought it might be helpful motivation –  ubpdqn Feb 23 at 3:03
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.