I need to map 2D measures taken at regular intervals in a room on the room floor plan in order to create a "heat map". Something like that:

enter image description here Taken from https://www.purrmetrix.com/category/advice/ -- for illustration purpose only

The room map can reasonably accurately be rendered as a polygon. However, I can't find:

  • how to create the continuous "heat map" from discrete samples (using bilinear interpolation between the samples),
  • nor how to put the room plan on the map, ensuring the "heat map" is clipped by the room boundaries.

I saw Mathematica has a full range of primitives to work with maps. But it seems there are more suitable to work with geodata, rather than simple 2D plans.

I didn't find really useful answers by searching on the net, probably because I lack the right keywords. Could you point me in the right direction?

  • 1
    $\begingroup$ Mapping functionality is for geographic computation. I doubt that it would apply easily here. Perhaps model the room as a Polygon, then generate a RegionMemberFunction from it, using RegionMember. Then use ListDensityPlot with that RegionMemberFunction as a RegionFunction option. If you had sample data, this would be easier to explain. $\endgroup$ – MarcoB Dec 17 '19 at 17:23
  • $\begingroup$ @Marco I've completely missed ListDensityPlot in the doc :/ $\endgroup$ – Sylvain Leroux Dec 17 '19 at 18:03

I mentioned in comments that I doubted that the mapping functionality would be appropriate here, but an easier approach would be to model the room as a Polygon, then generate and save RegionMemberFunction from it, using RegionMember. I would then use ListDensityPlot to present your data, with that RegionMemberFunction as a RegionFunction option. Here is an example of the approach I mentioned in comments, using some made up data.

First, generate the room outline as a Polygon and the corresponding RegionMemberFunction, as well as some fake data in the form $(x,y,value)$:

room = Polygon[{{0, 0}, {6, 0}, {6, 2}, {2, 2}, {2, 4}, {0, 4}}];
rmf = RegionMember[room];
fakedata = Table[{x, y, Sin[x] Cos[y]}, {x, -1., 8}, {y, -1., 5}]~Flatten~1;

Plot the data within the polygon, adding the room polygon as an outline:

    {FaceForm[], EdgeForm[Directive[Thickness[0.01], Black]], room},
    AspectRatio -> Automatic
    RegionFunction -> Function[{x, y, z}, rmf[{x, y}]],
    MaxPlotPoints -> 60

room and density plot

The MaxPlotPoints option within ListDensityPlot increases the precision of the drawing so that the density plot hews more closely to the shape of the room (the sharp corner was otherwise causing trouble).

| improve this answer | |
  • $\begingroup$ Thanks a lot, @Marco. I didn't expect such a detailed answer: this was exactly what I was looking for. $\endgroup$ – Sylvain Leroux Dec 17 '19 at 18:03
  • 1
    $\begingroup$ @Sylvain Great! Glad to hear that. $\endgroup$ – MarcoB Dec 17 '19 at 18:25

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.