I need my code to produce a graph of some function (just normal Plot, not Plot3D) with a mesh of 20 based on the x-values and alternating colors between green and yellow.
I have produced the following code:
Plot[x^3, {x, -20, 20},
PlotStyle -> Thick,
MeshStyle -> {Green, Yellow},
MeshFunctions -> {#1 &}, Mesh -> 20]
Can someone explain what the {#1&} means and how to make the colors alternate, because currently it is only making a yellow mesh.
MeshShading -> {Green, Yellow}see the docs on MeshFunctions >> Details on howMeshFunctionswork. – kglr Mar 03 '17 at 16:35... MeshStyle -> Red, MeshShading -> {Green, Yellow} ...; the two options do different things. Regarding the default mesh functions there is a table in MeshFunctions>> Details showing the default settings for various*Plot*functions. ForPlot, the default mesh function uses thexvalues (#1&is the first argument) – kglr Mar 03 '17 at 16:44Plot[x^3, {x, -20, 20}, PlotLabel -> "Title", PlotStyle -> Thick, MeshStyle -> {Directive[Green, PointSize[Medium]], Directive[Yellow, PointSize[Medium]]}, MeshFunctions -> {#1 &, #1 &}, Mesh -> {Range[-20, 20, 2], Range[-20, 20 , 4]}]– yode Mar 03 '17 at 16:49#&` see Slot – kglr Mar 03 '17 at 17:11#1and&, you can select each and execute the menu command Help > Find Selected Function. The second hits explain them, as well as the tutorial "Pure Functions" (third hit for#1). – Michael E2 Mar 04 '17 at 14:04