Re: Plot: Problem with Mesh Option

*To*: mathgroup at smc.vnet.net*Subject*: [mg102699] Re: [mg102661] Plot: Problem with Mesh Option*From*: "David Park" <djmpark at comcast.net>*Date*: Wed, 19 Aug 2009 07:03:17 -0400 (EDT)*References*: <32417776.1250593575981.JavaMail.root@n11>

This is a problem that hinges on some of the vagaries of Mathematica's adaptive plotting. Plot does not include the endpoints of the parameter range so the first and last time values in the Mesh specification are not on the curve. ParametricPlot does include the endpoints so the first and last points are on the curve and are included in the Mesh. But how is the average user supposed to know that? This "feature" is not spelled out in the documentation, and it might not persist in new versions. Mesh is a generally useful capability but here it is just getting in the way. It would be easier to just plot the curve and then plot the points. (Because how would the average user know to try ParametricPlot?) Instead of using the Show statement, which becomes rather convoluted when combining a number of curves and primitives, you could just use Epilog in the Plot statement. And you might as well plot all the points this way. timevector = Table[0.1*i, {i, 0, 10}]; Plot[Sin[t], {t, First[timevector], Last[timevector]}, Epilog -> {Directive[PointSize[Large], Red], Point[{#, Sin[#]}] & /@ timevector}] For those who use Presentations this might be easier to think of because drawing one thing after the other is the Presentations paradigm. So the equivalent statement would be: Needs["Presentations`Master`"] Draw2D[ {Draw[Sin[t], {t, First[timevector], Last[timevector]}], Directive[PointSize[Large], Red], Point[{#, Sin[#]}] & /@ timevector}, Axes -> True] And if you wanted to add other curves, say using other plot types, and primitives you just add them to the list or items to draw. Draw2D[ {Draw[Sin[t], {t, First[timevector], Last[timevector]}], Directive[PointSize[Large], Red], Point[{#, Sin[#]}] & /@ timevector, Black, ParametricDraw[{t, Cos[t]}, {t, First[timevector], Last[timevector]}], Text[Style[Cos[t], 14], {.2, Cos[.2]}, {0, 2}]}, Axes -> True] David Park djmpark at comcast.net http://home.comcast.net/~djmpark/ From: Benjamin Hell [mailto:hell at exoneon.de] Hi, I'm currently stuck on figuring out how to display the full mesh when manually defining it via passing a list of points, which looks like this: timevector = Table[0.1*i, {i, 0, 10}]; Plot[Sin[t], {t, First[timevector], Last[timevector]}, Mesh -> {timevector}, MeshStyle -> Directive[PointSize[Large], Red]] The whole thing works as expected, but the first and the last point of the mesh, which correspond to {0,Sin[0]} and {1,Sin[1]} in the example above, don't show up. So how can I fix that? Here is my further investigation: - The points of course do show up if I increase the time interval on both sides, let's say {t, First[timevector]-0.1, Last[timevector]+0.1} but this is not a proper solution to me. - Workarounds that do work: 1.Manually inserting the points in the Graphics output via a new Graphics object (not that nice): Show[ Plot[Sin[t], {t, First[timevector], Last[timevector]}, Mesh -> {timevector}, MeshStyle -> Directive[PointSize[Large], Red]], Graphics[{PointSize[Large], Red, Point[{First[timevector], Sin[First[timevector]]}], Point[{Last[timevector], Sin[Last[timevector]]}]}] ] 2.Using ParametricPlot instead of Plot (the best solution I found): ParametricPlot[{t, Sin[t]}, {t, First[timevector], Last[timevector]}, Mesh -> {timevector}, MeshStyle -> Directive[PointSize[Large], Red]] Thanks in advance, Benjamin