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 howMeshFunctions
work. $\endgroup$... 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 thex
values (#1&
is the first argument) $\endgroup$Plot[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]}]
$\endgroup$