ListPlot function in 2D- plan in two varibles

Suppose a function f[s,k]. How to Listplot this function in 2D plot in (s,k) plan, such that 1 < f[s,k] < 6 ?

This post is similar for : How to 2D-plot function in two varibles

However I have no here several regions for f[s,k], so I don't want to use Piecewise any more .. I think we may use If here, any help ?

• Do you mean like this: RegionPlot[1 < f[s, k] < 6, {s, -2, 2}, {k, -2, 2}]? Jun 21, 2016 at 12:40
• No, I want to make Listplot .. because you know the function will become as in the figures in the referred post , separate points ..
– S.S.
Jun 21, 2016 at 12:47
• Answer 1 in this post is fine , but only now there is no need for Piecewise .. it's only conditional function being plotted in its 2 variables plan ..
– S.S.
Jun 21, 2016 at 12:52

If the data is in {x,y,z} form you can use ListDensityPlot.

f[s_, k_] = Sin[s 2 Pi] Sin[k 2 Pi];
data = Flatten[Table[{s, k, f[s, k]}, {s, 0, 1, 0.05}, {k, 0, 1, 0.05}], 1];
ListDensityPlot[data, PlotLegends -> True]


If it is just a 2D array of data you can use MatrixPlot

f[s_, k_] = Sin[s 2 Pi] Sin[k 2 Pi];
data = Table[f[s, k], {s, 0, 1, 0.05}, {k, 0, 1, 0.05}];
MatrixPlot[data, PlotLegends -> True]


Or with discrete points

f[s_, k_] = Sin[s 2 Pi] Sin[k 2 Pi];
data = Flatten[Table[{s, k, f[s, k]}, {s, 0, 1, 0.1}, {k, 0, 1, 0.1}],    1];

min = Min@data[[All, 3]]; max = Max@data[[All, 3]];

Grid[{{Graphics[{ColorData["Rainbow"][(#[[3]] - min)/(max - min)],
PointSize[Large], Point[#[[1 ;; 2]]]} & /@ data,
ImageSize -> 300, Frame -> True],  BarLegend[{"Rainbow", {min, max}}]}}]


You can choose any colorscheme you want.

• Thanks, but I'd like to plot List of points instead
– S.S.
Jun 21, 2016 at 12:56
• Your data is {x,y,z} format? Jun 21, 2016 at 12:57

Since you only have one criterion, this will do if I understand correctly:

ListPlot[Table[{s, If[1 < f[s,k] < 6, k, Null]}, {s, smin, smax, ds}, {k, kmin, kmax, dk}]]

• Can't we just use the code in the referred post (Answer 1), but avoid Piecewise ?
– S.S.
Jun 21, 2016 at 13:17
• My understanding of that referred code was that you color the points {s, k} and the color is chosen based on what criterion is satisfied. Here there is only one criterion, so why bother with custom styles if all points will have the same color? Or do you want one color for 1 < f[s,k] < 6 and another for Not[1 < f[s,k] < 6]? Jun 21, 2016 at 13:22