First we load the data file

data = ReadList["data_smp.out", Number, RecordLists -> True];

I know that I should provide some sample data but in this case the structure of the list is too complicated that I cannot easily replicate them with random distributions. The complete data file can be obtained here data.

Then we use some criteria in order to define different colors to data

getColor[m_List, i_Integer] := 
 Module[{s = m[[i, 6]]}, 
 Which[s == 11, Green, s == 12, Darker[Green], s == 21, Yellow, 
 s == 22, Orange, s == 31, Pink, s == 32, Lighter[Magenta], 
 s == 99, Brown, s == 1, White, s == 2, Red, s == -1, White]];

and then we plot them

data2 = Table[{PointSize[0.005], getColor[data, i], 
Point[{data[[i, 1]], data[[i, 2]]}]}, {i, 1, Length[data]}];

g1 = Graphics[data2];

This is the output

enter image description here

Then some additional coloring

valrange = {-2, 4};
data[[All, 3]] = Rescale[Log10[data[[All, 3]]], valrange];
colfunc[x_, cf_] := 
If[(x[[5]] == 0 || x[[5]] == 1 || x[[5]] == 2), White, ColorData[cf][1 - x[[3]]]];

and the second plot

g2 = Graphics[{PointSize[0.005], 
Point[#[[1 ;; 2]], VertexColors -> colfunc[#, "DeepSeaColors"]] & /@
 data}];

enter image description here

Now if I want to combine these two plots with Show like

Show[g1, g2]

only the second plot (g2) is plotted. Why? Any ideas?

  • 2
    Isn't every point in g1 and g2 the same? So when you show them every point in g1 is underneath a point in g2. If you Show[g2, g1] I assume you just see g1? – Ymareth Nov 4 '14 at 8:48
  • 2
    Please provide a minimal working example, the data file is huge. By doing so, you might even find the mistake by yourself. The problem is that the upper image has no transparent regions. Please also tell us what you expect to see. – Philipp Nov 4 '14 at 8:49
  • @Ymareth In g2 plot there are some white areas. These white area should be replaced by g1. g1 and g2 are two pieces of the same puzzle which fit perfectly. – Vaggelis_Z Nov 4 '14 at 8:53
  • So far as I can see you're plotting the same {x, y} points each time. Once with a Table and once with a Map but in both cases, unless you're redefining data somewhere you haven't shown, your plots are simply differently colored versions of the same points. – Ymareth Nov 4 '14 at 8:56
  • @Ymareth Yes, I'm plotting the same (x,y) coordinates twice. But when I ask for Show[g2, g1] I should expect that g1 will be plotted above g2. Am I right? How can I achieve this superposition? – Vaggelis_Z Nov 4 '14 at 8:59
up vote 7 down vote accepted

You need to replace White by Transparent:

data = ReadList["~/Downloads/data_smp.out", Number, RecordLists -> True];
getColor[m_List, i_Integer] := Module[{s = m[[i, 6]]}, 
   Which[s == 11, Green, s == 12, Darker[Green], s == 21, Yellow, 
    s == 22, Orange, s == 31, Pink, s == 32, Lighter[Magenta], 
    s == 99, Brown, s == 1, Transparent, s == 2, Red, s == -1, Transparent]];
data2 = Table[{PointSize[0.005], getColor[data, i], Point[{data[[i, 1]], data[[i, 2]]}]}, {i, 1, Length[data]}];
g1 = Graphics[data2];
valrange = {-2, 4};
data[[All, 3]] = Rescale[Log10[data[[All, 3]]], valrange];
colfunc[x_, cf_] := If[(x[[5]] == 0 || x[[5]] == 1 || x[[5]] == 2), Transparent, ColorData[cf][1 - x[[3]]]];
g2 = Graphics[{PointSize[0.005], 
    Point[#[[1 ;; 2]], VertexColors -> colfunc[#, "DeepSeaColors"]] & /@ data}];
Show[{g1, g2}]

enter image description here

Here is an alternative approach using Select following @Ymareth's suggestion

getColor[m_List, i_Integer] := 
Module[{s = m[[i, 6]]}, 
Which[s == 11, Green, s == 12, Darker[Green], s == 21, Yellow, 
s == 22, Orange, s == 31, Pink, s == 32, Lighter[Magenta], 
s == 99, Brown, s == 1, White, s == 2, Red, s == -1, White]];

data2 = Table[{PointSize[0.005], getColor[data, i], 
Point[{data[[i, 1]], data[[i, 2]]}]}, {i, 1, Length[data]}];
g1 = Graphics[data2];

data3 = Select[data, #[[5]] == -1 &];
valrange = {-2, 4};
data3[[All, 3]] = Rescale[Log10[data3[[All, 3]]], valrange];
colfunc[x_, cf_] := ColorData[cf][1 - x[[3]]];

g2 = Graphics[{PointSize[0.005], 
   Point[#[[1 ;; 2]], 
   VertexColors -> colfunc[#, "DeepSeaColors"]] & /@ data3}];

enter image description here

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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