Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just tried something straightforward (for me):

dummy = Import["", "List"] & /@ col;
colors = dummy[[1]];
Graphics[{colors, Rectangle[{0, 0}]}]

Is it not possible to import color data from a file?

share|improve this question
it works fine if you remove & /@ col at the end of the first line. – kglr Jun 3 '14 at 20:10
Ok I don't know much but now there is nothing happening. No output at all. Which is very weird when it works fine with you. It states "RGBColor[0, 0, 1] is not a Graphics primitive or directive" – user3683367 Jun 3 '14 at 20:17
I think it is because your colors is a string; to change it to a color directive use ToExpression@colors... – kglr Jun 3 '14 at 20:25
Or just color = << "". – Rahul Jun 3 '14 at 20:25
@user3683367 - you oversimplified your question. what does your file to be imported REALLY look like? does it contain DIFFERENT colors, a list of colors ? But even in this case: How, exactly, do you want to color ONE rectangle with these different colors? – eldo Jun 3 '14 at 20:40
up vote 3 down vote accepted

I think you need something like the following:

 dummy = Import["", "List"];
 colors = ToExpression /@ dummy;
 Graphics[Thread[{colors, Rectangle/@ RandomInteger[10, {5, 2}]}]]

enter image description here

share|improve this answer
Yes this is exactly what I wanted. Would you recommend using "Thread" or "Sequence" like in the following question:… – user3683367 Jun 3 '14 at 21:38
@user3683367, you probably will be using this in an animation similar to the linked question; so i would recommend using the same setup... that is, {colors[[t]],Rectangle @@ (rectCoords[[t]])} with t the index you use in Animate or Table... – kglr Jun 3 '14 at 21:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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