1
$\begingroup$

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 ?

$\endgroup$
  • $\begingroup$ Do you mean like this: RegionPlot[1 < f[s, k] < 6, {s, -2, 2}, {k, -2, 2}]? $\endgroup$ – Coolwater Jun 21 '16 at 12:40
  • $\begingroup$ No, I want to make Listplot .. because you know the function will become as in the figures in the referred post , separate points .. $\endgroup$ – S.S. Jun 21 '16 at 12:47
  • $\begingroup$ 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 .. $\endgroup$ – S.S. Jun 21 '16 at 12:52
2
$\begingroup$

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]

enter image description here

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]

enter image description here

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}}]}}]

enter image description here

You can choose any colorscheme you want.

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

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}]]
$\endgroup$
  • $\begingroup$ Can't we just use the code in the referred post (Answer 1), but avoid Piecewise ? $\endgroup$ – S.S. Jun 21 '16 at 13:17
  • $\begingroup$ 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]? $\endgroup$ – Marius Ladegård Meyer Jun 21 '16 at 13:22

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.