5
$\begingroup$

I would like to plot a RegionPlot for $f(x,y) > 0$ where instead of specifying the range of $x$ and $y$ I want to use a list of {{x1,y1},{x2,y2}...,{xn,yn}} points that I have, as the inputs.

Any suggestions on how to do this would be great!

$\endgroup$
3
$\begingroup$

ConvexHullMesh may be what you are looking for:
"The convex hull mesh is the smallest convex set that includes the points..."

list = RandomReal[{-2, 2}, {100, 2}];
Show[ListPlot[list], RegionPlot[ConvexHullMesh[list]]]

enter image description here

Or did you mean something more like this:

region = Polygon[{{-1, -1}, {1.5, 0}, {-2, 2}}];
f[x_, y_] = E^-(x^2 + y^2);
Plot3D[If[RegionMember[region, {x, y}], f[x, y], Indeterminate], {x, -2, 2}, {y, -2, 2}]

enter image description here

| improve this answer | |
$\endgroup$
2
$\begingroup$

Assuming you have a list of $(x_i,y_i)$ values

list = RandomReal[{-2, 2}, {100, 2}];

We can get the range using MinMax for each axis.

MinMax /@ Transpose[list]

Or using CoordinateBounds, with identical results (credit to Carl Woll for pointing this out in the comments).

CoordinateBounds[list]

Now we can use that as an argument for RegionPlot taking advantage of Sequence and Apply (@@)

RegionPlot[
   x^2 + y^2 < 2
   , {x, Sequence @@ #1}
   , {y, Sequence @@ #2}
   ] & @@ CoordinateBounds[list]

Mathematica graphics

| improve this answer | |
$\endgroup$
  • 2
    $\begingroup$ In M10.1+ you could instead use CoordinateBounds. $\endgroup$ – Carl Woll Jun 5 '18 at 20:52
  • $\begingroup$ @CarlWoll Thanks, answer updated. $\endgroup$ – rhermans Jun 5 '18 at 20:57
1
$\begingroup$

I think this will do what you are asking for:

f[x_, y_] = Cos[2*2*3.14 Sqrt[x ^2 + y^2]];
list = {{0, -0.5}, {-1, 1}, {1, 1}};
xrange = {x, Min[list[[;; , 1]]], Max[list[[;; , 1]]]};
yrange = {y, Min[list[[;; , 2]]], Max[list[[;; , 2]]]};
RegionPlot[f[x, y] > 0 && RegionMember[Polygon[list], {x, y}], xrange, yrange]

enter image description here

| improve this answer | |
$\endgroup$
1
$\begingroup$

You can use ImplicitRegion[f[x, y] > 0, {x, y}] as the first argument in RegionPlot with the option PlotRange -> CoordinateBounds[pts] without having to specify the ranges of x and y:

f[x_, y_] := 1 - (x^2 + y^2)
pts = RandomReal[{-5, 5}, {30, 2}];
RegionPlot[ImplicitRegion[f[x, y] > 0, {x, y}], PlotRange->  CoordinateBounds[pts]]

enter image description here

Alternatively, use PlotRange -> PlotRange[ListPlot @ pts]:

RegionPlot[ImplicitRegion[2 - x^2 - y > 0, {x, y}], PlotRange -> PlotRange[ListPlot@pts]]

enter image description here

| improve this answer | |
$\endgroup$

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.