0
$\begingroup$

So, my problem is the following: I have the following table

tableresults = Table[{x, y, If[xpto < 0, -1, 
               If[xpto > 0, 1, 0]]}, {x, 0, 1, 0.001}, {y, 0, 1, 0.001}]

Where "xpto" is a function of x and y. So, now I want to plot the points {x,y} according to a color defined by the third value. This would mean that every point would be either, for instance, red if 1, blue if -1, and black if 0. The problem is that I have no idea how to do it. I try to explore the function ColorFunction, but this didn't produce the results wanted. Anyone can help?

$\endgroup$

closed as off-topic by Michael E2, user9660, MarcoB, ilian, Öskå Mar 3 '16 at 21:15

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Michael E2, Community, MarcoB, ilian, Öskå
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Have you seen ArrayPlot's option ColorRules? (You can also use the option DataRange to adjust the axes ranges, if desired.) $\endgroup$ – Michael E2 Mar 3 '16 at 13:36
  • 1
    $\begingroup$ Did you know there's a Sign[] function? $\endgroup$ – J. M. is away Mar 3 '16 at 13:51
2
$\begingroup$

I don't have your xpto function, so I'll use a random choice,

tableresults = 
  Table[{x, y, RandomChoice[{-1, 0, 1}]}, {x, 0, 1, 0.01}, {y, 0, 1, 
    0.01}];

You can get what you are looking for via ListPlot

ListPlot[
 Style[{#1, #2}, #3 /. {-1 -> Blue, 0 -> Black, 1 -> Red}] & @@@ 
  Flatten[tableresults, 1]]

enter image description here

or ListDensityPlot

ListDensityPlot[Flatten[tableresults, 1], 
 ColorFunction -> (Which[# == -1, Blue, # == 0, Black, # == 1, 
     Red] &), InterpolationOrder -> 0, ColorFunctionScaling -> False]

enter image description here

or MatrixPlot

MatrixPlot[tableresults[[All, All, 3]], 
 ColorRules -> {-1 -> Blue, 0 -> Black, 1 -> Red}, 
 DataRange -> {{0, 1}, {0, 1}}]

enter image description here

$\endgroup$
0
$\begingroup$
xpto[x_, y_] := Sign[x + y - 1]
DensityPlot[xpto[x, y], {x, 0, 1}, {y, 0, 1}, ColorFunction -> (Blend[{Blue, Red}, #] &)]

Mathematica graphics

$\endgroup$

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