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 have one big list with many sublists inside. All sublists consist of three numbers. For example:

{{83, 85, 82}, {65, 49, 46}, {65, 76, 45}, {70, 65, 84}, {73, 72, 65}, {40, 84, 72}, {69, 79, 80}, {69, 78, 73}, {78, 71, 41}, {10, 10, 49}} 

This is part of a list and I want that each sublist is one point on graphic. For example RGB(83,85,82) is color of first pixel, then 65,49,46 is color of the next pixel and so on.

Is there any way to plot that list in such way that one sublist represents one color in RGB system and somehow to specify the width of a plot. Thanks.

share|improve this question
1  
You can't post a small section of your "big list"? –  J. M. May 23 '13 at 10:35
    
What do you mean? –  Aleksandar Bukva May 23 '13 at 10:40
    
Press F1, search for Plot, ListPlot, ImageSize and PlotStyle. Otherwise, please specify clearly what you want to do. –  Yves Klett May 23 '13 at 10:55
    
How do you expect us to help you if you don't give an example of what you're having a hard time with? –  J. M. May 23 '13 at 10:58
    
{{83, 85, 82}, {65, 49, 46}, {65, 76, 45}, {70, 65, 84}, {73, 72, 65}, {40, 84, 72}, {69, 79, 80}, {69, 78, 73}, {78, 71, 41}, {10, 10, 49}} This is part of a list and I want that each sublist is one point on graphic. For example RGB(83,85,82) is color of first pixel, then 65,49,46 is color of the next pixel and so on. –  Aleksandar Bukva May 23 '13 at 11:01

3 Answers 3

up vote 6 down vote accepted

Say your data is:

q = {{{1, 85, 82}, {65, 49, 1}, {65, 76, 255}, {70, 65, 84}, {73, 266, 65}, 
      {40, 84, 72}, {69, 79, 80}, {69, 78, 73}, {78, 71, 41}, {10, 10, 49}}}

Note that I added another level of list so that it would be in the proper form. Then you can display it as an image using the oddly named Image command:

Image[q, "Byte", ImageSize -> 200]

enter image description here

The option ImageSize controls how large the image is. The form "Byte" is used to specify that your data is in the form of integers in the range 0-255 rather than the more common 0-1 range.

You can read all about these kind of commands by taking a word like Image and pressing the F1 (help) key. There are lots of options to choose from. If you wan to learn more about this kind of thing, the image processing tutorial is pretty good.

For example, you can arrange the pixel values in a 2D array. Here we construct a random set of values in a 2 row by 5 column array, each of which is specified by a 3-tuple of values, and then visualize using Image

w = RandomInteger[{1, 255}, {2, 5, 3}]
Image[w, "Byte", ImageSize -> 200]

enter image description here

share|improve this answer
    
This is exactly what I want, thank you :D –  Aleksandar Bukva May 23 '13 at 11:49
    
I have my list inside list1 and when I added another level of list list2={list1} and tried Image[list2, "Byte", ImageSize -> 100] I only got big blank output. –  Aleksandar Bukva May 23 '13 at 12:05
    
Look at the form I used above, and make sure the lists are nested properly. –  bill s May 23 '13 at 12:14
    
In your example you have 10 pixels, I would like to put those pixels in two rows 5 in each. –  Aleksandar Bukva May 23 '13 at 12:18
    
Try this one: q = {{{1, 85, 82}, {65, 49, 1}, {65, 76, 255}, {70, 65, 84}, {73, 266, 65}}, {{40, 84, 72}, {69, 79, 80}, {69, 78, 73}, {78, 71, 41}, {10, 10, 49}}} I've now made it a matrix of 3-tuples, which is the needed form. Or try this one: q = RandomReal[1, {2, 5, 3}] You can find this last example in the help file for Image. –  bill s May 23 '13 at 12:36

Generate some friendly colors (your list works just as well, but keep in mind that you usually want RGB values between 0 and 1 for Raster):

colors = Table[List @@ ToColor[Hue[h], RGBColor], {h, 0, 1, 0.1}]
(*{{1., 0., 0.}, {1., 0.6, 0.}, {0.8, 1., 0.}, {0.2, 1., 0.}, {0., 1., 
  0.4}, {0., 1., 1.}, {0., 0.4, 1.}, {0.2, 0., 1.}, {0.8, 0., 
  1.}, {1., 0., 0.6}, {1., 0., 0.}}*}
Graphics[Raster[Transpose[List /@ (colors)]], ImageSize -> 600]

enter image description here

share|improve this answer
3  
I want the Image Uploader back NOW! –  Yves Klett May 23 '13 at 11:19

Here is another method. With your RGB data in a:

SeedRandom[3]
a = RandomInteger[255, {10, 3}]

Merely:

ArrayPlot[{255 - a}]

enter image description here

Or split on two rows:

ArrayPlot[ Partition[255 - a, 5] ]

enter image description here

See ArrayPlot for options.

share|improve this answer
    
darn - short and sweet! –  Yves Klett May 23 '13 at 13:53
    
@Yves Thanks! :-) –  Mr.Wizard May 23 '13 at 13:54
    
Now there's a function that would be useful: SplitInto[lst, n] or PartitionInto[lst, n] where it would partition a list into n sublists of equal length. Additional settings would be needed to deal with non-divisible splits, but that's just details. +1, btw. –  rcollyer May 23 '13 at 13:55
    
@rcollyer you mean like this? –  Mr.Wizard May 23 '13 at 13:58
    
@rcollyer yes, Partition is already up to that - I always struggle to remember the syntax, though :-) –  Yves Klett May 23 '13 at 14:21

Your Answer

 
discard

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.