Matrix plot using RGB color coding

I am looking to plot a line of 250 discrete sites with a specified RGB color value based on the import file values. The import file has the following format: I want the first element in each row to be the blue color value, and the 2nd element to be the red color value. For, example, the color of the first site would be (0.8, 0, 0.1) using RGB color.

I am trying to use MatrixPlot with the color function, but I can't seem to get it working. I cant seem to get the color function to line up with each site, and loop through all of the sites. I have a simple model up and running where the import file is just 1 column of 0,1,2 with 0=white, 1=red,2=blue, and looks like I just can't seem to figure out how to do matrix plot for each site using the RGB value plot based on 2 values.

• Each row of the import file is a site. So row 1 is site 1, row 2 is site 2, etc – Sean Jan 22 '18 at 17:59
• it would be helpful if you provide some code you have tried thus far together the data (or partial)... – José Antonio Díaz Navas Jan 22 '18 at 18:02
• list = {{0.8, 0.1}, {0.2, 0.4}, {0.3, 0.3}, {0.1, 0.1}, {0.9, 0.0}, {0.5, 0.1}, {0.1, 0.5}, {0.3, 0.4}, {0.4, 0.2}};RGBColor[#] & /@ (Insert[#, 0, 2] & /@ list) – Okkes Dulgerci Jan 22 '18 at 18:13
• (0.8, 0, 0.1) should be (0.1, 0, 0.8), since RGB={Red,Green,Blue} – Okkes Dulgerci Jan 22 '18 at 18:27

With simulated data:

data = Table[{RandomReal[], RandomReal[]}, {n, 250}];
colorrules = Flatten@Table[{i -> (RGBColor[#[], 0, #[]] & /@ data)[[i]]},
{i, Length[data]}];
MatrixPlot[{Range[Length@data]}, ColorRules -> colorrules,
FrameTicks -> {{None, None}, {Automatic, Automatic}}] • Awesome! This is exactly what I was looking for! Thank you Jose – Sean Jan 23 '18 at 16:00

you can also use ColorFunction to specify color in MatrixPlot

data = RandomReal[{0, 1}, {100, 2}];
color[i_] := RGBColor[data[[i, 2]], 0, data[[i, 1]]]
MatrixPlot[{Range@Length@data}, ColorFunctionScaling -> False,
ColorFunction -> color ]


A matrix of number pairs:

data = RandomReal[1, {10, 10, 2}];


Insert 0 in the middle of each entry:

data2 = Apply[{#, 0, #2} &, data, {-2}];


Use directly (without having to wrap each entry with RGBColor) as input in Image:

Image[data2, ImageSize -> 300] Or use the combination Graphics @ Raster@#:

Graphics[Raster[Reverse@data2], ImageSize -> 300] Rows are reversed to get the same picture as the output of Image.

list = RandomReal[{0, 1}, {250, 2}];

col = # -> (RGBColor[#] & /@ (Insert[#, 0, 2] & /@ list))[[#]] & /@
Range@Length@list;

ArrayPlot[{Range@Length@list}, ColorRules -> col,
FrameTicks -> {{All, All}, {Automatic, Automatic}}, ImageSize -> 800] or MatrixPlot

MatrixPlot[{Range@Length@list}, ColorRules -> col,
FrameTicks -> {{All, All}, {Automatic, Automatic}}, ImageSize -> 800] 