Message Boards Message Boards

0
|
5210 Views
|
2 Replies
|
4 Total Likes
View groups...
Share
Share this post:

When I show a ListPlot and a Plot for the same function the graph is wrong.

Posted 11 years ago
Show[Plot[x^3, {x, 0, Pi}] ,
ListPlot[Table[x^3, {x, 0.0, Pi, 0.1}],
DataRange -> {0, Pi}]]

The graphs are slightly off and I don't understand why.

Can anyone help me understand what I have to do if I want the graphs to match perfectly?
POSTED BY: David Gustafson
2 Replies
The first point in your ListPlot is {0,0}, which is fine.  The last point is {Pi, 3.1^3} instead of {Pi, Pi^3}, and while this might seem like a small difference, it's noticeable with regard to the curve from Plot.

Two possible solutions are to either generate the points as {x,y} pairs, in which case you don't need DataRange:
ListPlot[Table[{x, x^3}, {x, 0.0, Pi, 0.1}]]
or to use a setting for DataRange that accurately reflects the range of x-values for the data you're plotting:
ListPlot[Table[x^3, {x, 0.0, Pi, 0.1}], DataRange -> {0, 3.1}]
POSTED BY: Brett Champion
Posted 11 years ago
Thanks Brett.  I really appreciate the help.
POSTED BY: David Gustafson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract