3
$\begingroup$

Disclaimer: I am new to Mathematica and this is my first post here! I am trying to plot EEG data of different intensities of brain waves from an FFT to areas of the brain where they were collected. I am trying to find the right code that will enable the data to be represented within a region that is horseshoe-shaped. The data was collected along on the outer edge of the horseshoe shape. So this is the what I tried to do:

ListDensityPlot[{{-1.2, 0, 22}, {1.2, 0, 16}, {0, 1.5, 34}},

RegionFunction -> Function[{x, y}, 0.5 < (x^2)/2 + (y^2)/3 < 1]] 

However, the output is a triangle formed by the points where the data was collected.

Can anyone think of a way to make the density plot appear inside of the horseshoe-shaped region? Maybe I could use an image in Mathematica that the data could be plotted over? I really don't know what would be the best way to do this. Any help would be appreciated! Thank you!

$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, [by clicking the checkmark sign](tinyurl.com/4srwe26 $\endgroup$ – Dunlop Feb 20 at 4:31
  • $\begingroup$ Try playing around with 'DataRange' i.e. 'DataRange -> {{-1.2, 1.2}, {0, 1.5}}'. This may help. You may also have issues with the small number of data points that you have within this region. The 'ListDensityPlot' needs to interpolate data within the range of the plot points that you have and with only 3 points , any points outside of the triangle make little sense $\endgroup$ – Dunlop Feb 20 at 4:32
4
$\begingroup$

The sparse data provided in the question yields the density plot,

dp = ListDensityPlot[{{-1.2, 0, 22}, {1.2, 0, 16}, {0, 1.5, 34}}]

enter image description here

There is insufficient data to create a density plot by interpolation in the white areas. The question then asks how to plot only that part of the density plot in the red region,

ContourPlot[(x^2)/2 + (y^2)/3, {x, -1.2, 1.2}, {y, 0, 1.5}, 
    ContourStyle -> White, Contours -> {1/2, 1}, ContourShading -> {White, Red}]

enter image description here

This contour plot can be converted into a stencil of sorts by replacing Red by None (i.e., a clear region) and superimposing it on the density plot:

st = ContourPlot[(x^2)/2 + (y^2)/3, {x, -1.2, 1.2}, {y, 0, 1.5}, 
    ContourStyle -> White, Contours -> {1/2, 1}, ContourShading -> {White, None}]
Show[dp, st]

enter image description here

More data for the original ListDensityPlot would fill out the horse-collar region.

Addendum

To demonstrate, let us linearly extrapolate the data in the question by

if = Interpolation[{{-1.2, 0, 22}, {1.2, 0, 16}, {0, 1.5, 34}}, InterpolationOrder -> All];
tt = DensityPlot[if[x, y], {x, -1.2, 1.2}, {y, 0, 1.5}];
Show[tt, st]

enter image description here

Of course, if Interpolation is to be used as an intermediate step, then the code in the question, appropriately modified, produces essentially the same plot.

DensityPlot[if[x, y], {x, -1.2, 1.2}, {y, 0, 1.5}, 
    RegionFunction -> Function[{x, y}, 0.5 < (x^2)/2 + (y^2)/3 < 1]]
| improve this answer | |
$\endgroup$
3
$\begingroup$

You can wrap ListDensityPlot output with Texture and use it as the PlotStyle setting in RegionPlot:

llp = ListDensityPlot[{{-1.2, 0, 22}, {1.2, 0, 16}, {0, 1.5, 34}}, ImageSize -> Medium];

texture = Texture[Show[llp, PlotRangePadding -> 0, Frame -> False]];

rp = RegionPlot[0.5 < (x^2)/2 + (y^2)/3 < 1, {x, -1.2, 1.2}, {y, 0, 1.5}, 
   PlotStyle -> texture, BoundaryStyle -> None, ImageSize -> Medium];

Row[{llp, rp}, Spacer[10]]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Nice answer (+1). $\endgroup$ – bbgodfrey Feb 20 at 14:27
  • $\begingroup$ Thank you @bbgodfrey. I like your ContourPlot approach better. $\endgroup$ – kglr Feb 20 at 18:03

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.