# Converting between types of Graphics

The above title will probably not be unfamiliar to the readers of The Mathematica Book 5, the former being the topic of the Section 7, Chapter 9, Part 1 of the latter, where three functions are provided: ContourGraphics, DensityGraphics, and SurfaceGraphics.

It was shown there that, e.g., the output of Plot3D can be transformed into one like the output of ContourPlot by ContourGraphics. But the problem is that I only found the above three functions deprecated when I tried to figure out how to use them. And GraphicsComplex is claimed to be the new version function to do the job, the documentation of which, however, seems not covering the topic.

So, how to realize the conversions among the three kinds of graphics (outputs from ContourPlot, DensityPlot and Plot3D) in newer verions of Mathematica, say after V. 11?

Generally, it is easy but it is a bad idea. You need to extract the points from the Plot3D and feed it into the ListDensityPlot and ListContourPlot. You need to use the List variants of these functions since you operate on the numerical values and not on an expression. This is the main reason, why it is a bad idea. Here is the example from the book for newer versions of Mathematica

plot = Plot3D[BesselJ[nu, 3 x], {nu, 0, 3}, {x, 0, 3}];
points = Cases[plot, GraphicsComplex[pts_, ___] :> pts, Infinity];
dplot = ListDensityPlot[points];
cplot = ListContourPlot[points];

GraphicsRow[{plot, dplot, cplot}]


The reason why it is a bad idea is that nowadays, ContourPlot does a much better job when it has the expressions where it really can track the contours instead of estimating them from numerical values. Just compare the smoothness of the contour lines:

ContourPlot[BesselJ[nu, 3 x], {nu, 0, 3}, {x, 0, 3}]


For DensityPlot the problem is not so severe, but, still, I would suggest to let DensityPlot decide the sampling and give it the analytical expression.