Skip to main content
Tweeted twitter.com/StackMma/status/1480011685490475008
edited tags
Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
Became Hot Network Question
Source Link
MMA13
  • 4.8k
  • 3
  • 16
  • 25

ListDensityPlot with RegionFunction takes too long?

I am using ListDensityPlot with RegionFunction (MMA12.3 on Win 64) but it takes too long

region = Polygon[{{-(\[Pi]/3), -(\[Pi]/Sqrt[3])}, {-((2 \[Pi])/3), 
     0}, {-(\[Pi]/3), \[Pi]/Sqrt[3]}, {\[Pi]/3, \[Pi]/
      Sqrt[3]}, {(2 \[Pi])/3, 
     0}, {\[Pi]/3, -(\[Pi]/Sqrt[3])}, {\[Pi]/
      3, -(\[Pi]/Sqrt[3])}, {-(\[Pi]/3), -(\[Pi]/Sqrt[3])}}];
datr = Flatten[
   ParallelTable[{x, y, Cos[x] Sin[x y]}, {x, -2.5, 2.5, 
     0.05}, {y, -2.5, 2.5, 0.05}], 1];

here is the result without RegionFunction

ListDensityPlot[datr, 
  ColorFunction -> (Blend[{Orange, Gray, Black}, 
      Rescale[#, {-1, 1}]] &), InterpolationOrder -> 0, 
  ColorFunctionScaling -> False, 
  ClippingStyle -> Automatic] // AbsoluteTiming    

enter image description here

and with

ListDensityPlot[datr, 
  ColorFunction -> (Blend[{Orange, Gray, Black}, 
      Rescale[#, {-1, 1}]] &), InterpolationOrder -> 0, 
  ColorFunctionScaling -> False, ClippingStyle -> Automatic, 
  RegionFunction -> 
   Function[{x, y}, {x, y} \[Element] region]] // AbsoluteTiming    

enter image description here