0
$\begingroup$

I would like to produce a single plot of a function defined over discrete points in [-1,1] as I increase the number of points while shrinking the distance.

f[x_,en_]:= -x^2;
data = Table[f[x,en],{en,10,50,10},{x,-1,1,2/en}]
ListPlot[data]

enter image description here

This is almost what I want, I get all the different run of f plotted with nice color, but the x-axis runs from 0 to 50 instead of going from -1 and 1.

I can obtain something closer to what I want if I do

data = Table[DiscretePlot[f[x,en],{x,-1,1,2/en}],{en,10,50,10}];
Show[data, PlotRange -> All]

but in this case all plots have the same color and are hard to distinguish

enter image description here

$\endgroup$
  • $\begingroup$ data = Table[{x,f[x,en]},{en,10,50,10},{x,-1,1,2/en}]; ListPlot[data]? $\endgroup$ – N.J.Evans Apr 18 '17 at 12:36
  • $\begingroup$ Almost, but not quite. I am now getting the color of the plot based on the x-coordinate (instead of it being based on en). $\endgroup$ – Three Diag Apr 18 '17 at 12:40
  • $\begingroup$ Ah no ok, got it! $\endgroup$ – Three Diag Apr 18 '17 at 12:42
  • $\begingroup$ Just add a DataRange -> {-1, 1} option to your ListPlot command $\endgroup$ – Gustavo Delfino Apr 18 '17 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.