1
$\begingroup$

I plot a graph by the code I wrote. The graph shows zeros of 4 equations. I want to make the graph colored: regions which both datas2r and datas2r are negative becomes gray, regions which datas1i OR datas2i are not zero AND both datas2r and datas2r are negative become yellow and regions that one of the datas2r or datas2r are not negative becomes red. Could anyone help? Any answers are highly appreciated. This is my code.

datas1i = Flatten[Table[{v, e, s1i}, {v , 0, 40, 1}, {e, 2100, 27000, 50}], 1];
datas2r = Flatten[Table[{v, e, s2r}, {v , 0, 40, 1}, {e, 2100, 27000, 50}], 1];
datas1r = Flatten[Table[{v, e, s1r}, {v , 0, 40, 1}, {e, 2100, 27000, 50}], 1];
datas2i = Flatten[Table[{v, e, s2i}, {v , 0, 40, 1}, {e, 2100, 27000, 50}], 1]; 
p1 = ListContourPlot[datas1i, ContourShading -> False, Contours -> {0}, ContourStyle -> Red]; p2 = ListContourPlot[datas2r, ContourShading -> False, Contours -> {0}, ContourStyle -> Blue]; 
p3 = ListContourPlot[datas1r, ContourShading -> False, Contours -> {0}, ContourStyle -> Green]; 
p4 = ListContourPlot[datas2i, ContourShading -> False, Contours ->{0}, ContourStyle -> Black]; 
Show[p1, p2, p3, p4, FrameStyle -> Directive[Black, 30]]
$\endgroup$
  • $\begingroup$ I didn't underestand what do you mean? @Feyre $\endgroup$ – sara nj Jan 16 '17 at 9:53
  • $\begingroup$ The term Graph[] is a built in function in MMA, and using that word to describe what you're doing with ContourPlot[] is misleading. I retract my previous comment, as datas1i etc are quite long. $\endgroup$ – Feyre Jan 16 '17 at 9:55
  • 1
    $\begingroup$ Your gray and yellow region conditions are not mutually exclusive, and thus the regions are not disjoint. If the yellow supersedes the gray, then generically what is painted gray won't be a (2D) region, but a set of points lying in the yellow (where both data1i, data2i are zero). If it is not a discrete set, but a line or a full-dimensional region, then I would need to see the data to understand. From a computational-graphics point of view, there is a big difference between sets of different dimensions. $\endgroup$ – Michael E2 Jan 16 '17 at 13:43
  • 1
    $\begingroup$ You got answers for 13 out of 24 questions and you have accepted only one answer so far. Why is that? Are you not satisfied with the answers or there is something else going on? $\endgroup$ – zhk Jan 16 '17 at 14:10
  • 1
    $\begingroup$ Then you should comment on it showing your dissatisfaction and explain what exactly you want. The problem is that unanswered questions are pop up again n again. BTW, I am surprised that 12 answers are incomplete by your standard. $\endgroup$ – zhk Jan 16 '17 at 14:32
1
$\begingroup$

The question then is to find, and plot a region subject to a certain condition of two data sets:

Suppose we have as datasets:

datas1r = 
  Flatten[Table[{i, j, Sin[i + j^2]}, {i, 0, 3, 0.1}, {j, 0, 3, 0.1}],
    1];
datas2r = 
  Flatten[Table[{i, j, Cos[i + j^2]}, {i, 0, 3, 0.1}, {j, 0, 3, 0.1}],
    1];
datas1i = 
  Flatten[Table[{i, j, Tan[i + j^2]}, {i, 0, 3, 0.1}, {j, 0, 3, 0.1}],
    1];
datas2i = 
  Flatten[Table[{i, j, Cosh[i + j^2]}, {i, 0, 3, 0.1}, {j, 0, 3, 
     0.1}], 1];

with:

p1 = ListContourPlot[datas1i, ContourShading -> False, 
   Contours -> {0}];
p2 = ListContourPlot[datas2r, ContourShading -> False, 
   Contours -> {0}];
p3 = ListContourPlot[datas1r, ContourShading -> False, 
   Contours -> {0}];
p4 = ListContourPlot[datas2i, ContourShading -> False, 
   Contours -> {0}];

Which are of the same form as the question.

We can find where these two are both not negative with Select[] We can generate a region from these points, and plot it.

datag = Select[Transpose[{datas1r, datas2r}], 
   Last@#[[1]] < 0 && Last@#[[2]] < 0 &];
regiong = datag[[All, 2, 1 ;; 2]];
grey = RegionPlot[DelaunayMesh@regiong, 
   PlotStyle -> RGBColor[0.5, 0.5, 0.5], 
   BoundaryStyle -> RGBColor[0.4, 0.4, 0.4]];
datar = Select[Transpose[{datas1r, datas2r}], 
   Last@#[[1]] > 0 || Last@#[[2]] > 0 &];
regionr = datar[[All, 2, 1 ;; 2]];
red = RegionPlot[DelaunayMesh@regionr, 
   PlotStyle -> RGBColor[0.8, 0.4, 0.4], 
   BoundaryStyle -> RGBColor[0.5, 0.2, 0.2]];
datay = Select[
   Transpose[{datas1i, datas2i, datas1r, 
     datas2r}], (Last@#[[1]] != 0 || 
       Last@#[[2]] != 0) && (Last@#[[3]] < 0 && 
       Last@#[[4]] < 0) &];
regiony = datay[[All, 2, 1 ;; 2]];
yellow = RegionPlot[DelaunayMesh@regiony, 
   PlotStyle -> RGBColor[0.6, 0.6, 0.2], 
   BoundaryStyle -> RGBColor[0.4, 0.5, 0.2]];

Which can then be added to the show:

Show[red, yellow, grey, p1, p2, p3, p4]

enter image description here

$\endgroup$
  • $\begingroup$ But what about the condition on datas1i and datas2i? could it be added to the show in the same way? $\endgroup$ – sara nj Jan 16 '17 at 12:19
  • $\begingroup$ @saranj Yes, but you need to change the Select[] criteria. to datai = Select[Transpose[{datas1r, datas2r}], Last@#[[1]] != 0 && Last@#[[2]] != 0 &]; $\endgroup$ – Feyre Jan 16 '17 at 12:22
  • $\begingroup$ I think your comment is not correct. Because I want "regions which datas1i OR datas2i are not zero AND both datas2r and datas2r are negative become yellow" $\endgroup$ – sara nj Jan 16 '17 at 13:08
  • $\begingroup$ Select[Transpose[{datas1i,dats2i, datas1r, datas2r}], (Last@#[[1]] != 0 || Last@#[[2]] != 0) && (Last@#[[3]] >= 0 && Last@#[[4]] >= 0) &]; $\endgroup$ – Feyre Jan 16 '17 at 13:11
  • $\begingroup$ and how does region (in your code) change? $\endgroup$ – sara nj Jan 16 '17 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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