# Custom mesh in ListPlot3D

I have the following data:

bData = {{0.05, 0, 3.0198054316361485}, {0.05, 0.55,
1.1092237487369552}, {0.05, 1., 0.835126287487935}, {0.05, 1.61,
0.3647962208597364}, {0.1, 0, 2.991741037155516}, {0.1, 0.55,
1.1270688044265789}, {0.1, 1., 0.8493688576645464}, {0.1, 1.61,
0.5932718812318991}, {0.15, 0, 2.8183386248853517}, {0.15, 0.55,
1.6096377385996246}, {0.15, 1., 1.1088595437185633}, {0.15, 1.61,
0.5368907021939747}}


I plot my data as follows:

p1 = ListPointPlot3D[bData, PlotStyle -> PointSize[Large]]
p2 = ListPlot3D[bData, MeshStyle -> Red, PlotStyle -> None,
Mesh -> All, InterpolationOrder -> 1(*,ClippingStyle\[Rule]None*),
PlotRange -> All]
Show[{p1, p2}]


What I want to achieve with this is to show the data points clearly and also connect them in the x and y direction with simple lines.

I have done the following   I would like to remove all the diagonal lines and just connect the points in the x and y directions.

If I do Mesh->Full, I get the following: Is there also a way of marking the vertices, without having to superpose two different plots? That complicates the labelling and legending I also want.

• Why do you have InterpolationOrder->10 if all you want are the lines connecting the data points? – Michael E2 Mar 6 '13 at 1:00
• No, it was just a mistake I did when I copied it, because I was playing with that number before, but actually it doesn't change the output of my question above. – Santiago Mar 6 '13 at 6:56

You can add the mesh specific to the x and y coordinates of your data with Mesh -> {First /@ bData, #[] & /@ bData}:

p1 = ListPointPlot3D[bData, PlotStyle -> PointSize[Large]]
p2 = ListPlot3D[bData, MeshStyle -> Red, PlotStyle -> None,
Mesh -> {First /@ bData, #[] & /@ bData},
InterpolationOrder -> 10(*,ClippingStyle->None*), PlotRange -> All]
Show[{p1, p2}] ---EDIT---

Just saw the added requirement for labels so need to comply before @VLC (who beat me to the answer by some seconds) sees it :)

labels = Graphics3D[
Text[ToString@Round[#, .1], #, {-1.5, 1.5}]] & /@ bData;


the first slot within Text is what you see (so I round it to the first decimal point so that it doesn't look too crammed), the second is the actual coordinates for the placement of the text, and the third is an offset so as not to fall on the points. Now

Show[{p1,p2,labels}] I don't know how you can avoid making one plot for the mesh and one for the points. In 2d Graphics, you'd normally add the points as an epilog to ListPlot so that they show over your lines but in 3d graphics I don't think you can do this.

• Nice labelling. Good answer, I just have to practice a bit more how to write code with short forms. – Santiago Mar 5 '13 at 20:39

With your data you could try to specify the divisions of the Mesh to match your x and y coordinates:

p1 = ListPointPlot3D[bData, PlotStyle -> PointSize[Large]];
p2 = ListPlot3D[bData, MeshStyle -> Red, PlotStyle -> None,
Mesh -> {Union[bData[[All, 1]]], Union[bData[[All, 2]]]},
InterpolationOrder -> 10, PlotRange -> All];
Show[p1,p2] • Really simple solution, nice – Santiago Mar 6 '13 at 16:16

ListPlot3D generates output of the form Graphics3D[GraphicsComplex[pts, g,...] so you can insert the points manually like this:

p = ListPlot3D[bData, MeshStyle -> Red, PlotStyle -> None,
Mesh -> {Union[bData[[All, 1]]], Union[bData[[All, 2]]]},(*InterpolationOrder\[Rule]10,*)
PlotRange -> All];
Insert[p, {ColorData, PointSize[Large], Point[Range[Length[bData]]],
Table[Text[bData[[i, 3]], i, {0, -1.3}], {i, Length[bData]}]}, {1, 2, -1}] Alternately, if the structure of bData is the same as the example (sorted by $x$ and then by $y$ coordinates, forming a grid) and all you want are the mesh lines, one can simply partition the data and draw the lines as follows:

xLines = Partition[bData, 4];
yLines = Transpose[xLines];
Graphics3D[{{Red, Line[xLines~Join~yLines]},
ColorData, PointSize[Large], Point[bData],
Table[Text[bData[[i, 3]], bData[[i]], {0, -1.3}], {i, Length[bData]}]},
BoxRatios -> {1, 1, 0.4}, Axes -> True, ImagePadding -> Scaled[0.05]]


The output is the same as above.

• Thanks for the nice and different approach, anyway I will take the other question, since it's more understandble for me at this point. – Santiago Mar 6 '13 at 16:15
• @Santi You're welcome. The other answers seem good, and you should accept the one that seems best to you. Each answer gives someone with a similar question to yours choices for which solution works best or can be adapted to their case. In comparing answers I often learn something new about Mathematica. – Michael E2 Mar 6 '13 at 17:18