Converting Mesh in DensityPlot to a Graph

If you don't mind using undocumented functions, you can do it like this:

Graphics`Mesh`MeshInit[];

mesh = DensityPlot[4 Sin[2 Pi x] Cos[1.5 Pi y] (1 - x^2) (1 - y) y, {x, -1, 1}, {y, 0, 1},
Method -> {"ReturnMeshObject" -> True}];

Graph[mesh["Edges"], VertexCoordinates -> mesh["Coordinates"], 
 VertexShapeFunction -> (Point[#] &)]

enter image description here


This will do

densPlot = 
  DensityPlot[
   4 Sin[2 Pi x] Cos[1.5 Pi y] (1 - x^2) (1 - y) y, {x, -1, 1}, {y, 0,
     1}, MeshStyle -> Thick, Mesh -> All];

vertexCoordinates = densPlot[[1, 1]];

length = Length[vertexCoordinates];

graphReadyConnections =
  DeleteDuplicates@
   Flatten[
    Cases[#, 
       List[x_, y_, z_] :> {Sort[x \[UndirectedEdge] y], 
         Sort[x \[UndirectedEdge] z], Sort[y \[UndirectedEdge] z]}, 
       Infinity] &@
     densPlot[[1, 2, 1, 1, 3, 1, 1, 1]]
    ,
    1
    ];

Graph[Range[length], graphReadyConnections, 
 VertexCoordinates -> vertexCoordinates, 
 VertexShapeFunction -> {Disk[#, 0.005] &}, ImageSize -> 800]

My modest attempt:

dp = DensityPlot[4 Sin[2 Pi x] Cos[3 Pi y/2] (1 - x^2) (1 - y) y,
                 {x, -1, 1}, {y, 0, 1}, Mesh -> All]

{verts, edgs} = List @@ MapAt[Composition[Union, Flatten],
        (Most[MapAt[Flatten[Cases[#, _Polygon, ∞]] &,
                    First[Cases[dp, _GraphicsComplex, ∞]], {2}]] /.
                    Polygon[p : {__?VectorQ}] :> Map[Polygon, p]) /.
         Polygon[p_] :> Map[Composition[Line, Sort], Partition[p, 2, 1, 1]], {2}]

Graph[Range[Length[verts]], edgs /. Line[l_] :> UndirectedEdge @@ l,
      VertexCoordinates -> verts, VertexShapeFunction -> {Point[#] &}]

graph from mesh

Compare:

Graphics[GraphicsComplex[verts, edgs]]

mesh lines from density plot