I have a density plot, for example


Then I would like to collect points from this densityplot into a file so that I can always use ListDensityPlot to draw these points again, or I may draw these points by some other software.

I read several posts on how to do that for Plot, but how can I generalize them to DensityPlot?

data = Reap[DensityPlot[Sin[x*y], {x, 0, 2 Pi}, {y, 0, 2 Pi}, 
     EvaluationMonitor :> Sow[{x, y, Sin[x*y]}]]][[2, 1]];


Mathematica graphics

compare to

 DensityPlot[Sin[x*y], {x, 0, 2 Pi}, {y, 0, 2 Pi}]

Mathematica graphics

  • $\begingroup$ Thanks! It works. I really need to learn more about Reap function. $\endgroup$ – user39954 Jul 11 '14 at 3:31
  • $\begingroup$ For each point {x,y} your solution evaluate the function f[x,y]' to DensityPlot` twice: one time for the DensityPlot value itself, and one for the Sow, as you put back f[x,y] in Sow. Is there a way to call f[x,y] on time only ? $\endgroup$ – Pierre Jul 13 '16 at 22:36
  • $\begingroup$ @PierreL. the only way to evaluate only once, that I know about, is to generate the data off-line using Table command, then use DensityPlot but the reason for doing the above, is to use the same sampling as that used by DensityPlot which can be different and not uniform as what one might pick using Table. Sometimes Plot uses an adaptive sampling. I $\endgroup$ – Nasser Jul 13 '16 at 23:59
  • $\begingroup$ @Nasser yes, unfortunately DensityPlot cannot return easily the values on the grid with the plot itself. $\endgroup$ – Pierre Jul 15 '16 at 16:14

how about this?

lists = Table[
   Sin[x*y], {x, 0, 2 \[Pi], \[Pi]/20}, {y, 0, 2 \[Pi], \[Pi]/20}];

ListDensityPlot[lists, Mesh -> None]

enter image description here

Or like this

lists = DensityPlot[Sin[x*y], {x, 0, 2 \[Pi]}, {y, 0, 2 \[Pi]}][[1, 

ListDensityPlot[{#1, #2, Sin[#1 #2]} & @@@ lists, Mesh -> None]
  • $\begingroup$ Thank you. So Table[] divides the domains {x,0,2pi} and {y,0,2pi} automatically? $\endgroup$ – user39954 Jul 11 '14 at 3:42
  • $\begingroup$ Automatical dividing number is '1', but If you make more dividing point, then do like this. $\endgroup$ – Junho Lee Jul 11 '14 at 5:32

Though DensityPlot only contains color info for z value.

However, you could obtain data from equivalent Plot3D

plot=Plot3D[Sin[x*y], {x, 0, 2 Pi}, {y, 0, 2 Pi}]

If you see the plot//FullForm, you can find point data contained in GraphicsComplex[list of data,__]

So to extract data, it is as simple as


You can check this by


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.