Suppose I need to plot Sin function:

Plot[Sin[x ], {x, -10 , 10 }]

Now I need to specify the resolution of the plot. I tried by using list Plot

ListPlot[Table[Sin[x ], {x, -10, 10, 0.01}], Joined -> True]

But here the x axis is different. In this case it plots from 0 to 20.

Now I have two questions,

  1. How to plot a function giving the specifications
  2. Is there any way to use ListPlot and get the axis as (-10,10).

Thanks in advance


closed as off-topic by Bob Hanlon, Edmund, m_goldberg, Carl Lange, MarcoB Jul 1 at 16:32

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Bob Hanlon, Edmund, m_goldberg, MarcoB
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ You can make the axes agreeby inputting the {x,y} data pairs: ListPlot[Table[{x, Sin[x]}, {x, -10, 10, 0.01}], Joined -> True] $\endgroup$ – bill s Jun 26 at 13:02
  • $\begingroup$ Are you wanting to control how many points are used to generate the plot? $\endgroup$ – chuy Jun 26 at 15:35

The reason ListPlot gives you 1 to 20 on the x-axis is that you've only specified y-values in the table. Try:

    {x, Sin[x]},
    {x, -10, 10, 0.1}

Plot of sin(x) with correct x-axis.

ListPlot expects data to be pairs of {x, y} coordinates. If they are not, it will assign the numbers 1 through n to the x-coordinate.

For using Plot, the "resolution" of the plot can be changed by adjusting PlotPoints and MaxRecursion. This code shows what happens as you change those values. The black points are the points that Plot is using to draw the curve. Of course, in your final plot you probably won't want to show those black dots. They will only show up if you have some specification for Mesh.

      {x, -10, 10},
      Mesh -> All,
      MeshStyle -> Directive[AbsolutePointSize[3], Black],
      PlotPoints -> i,
      MaxRecursion -> j
    {i, 2, 18, 4},
    {j, 1, 5, 1}
  TableHeadings -> {
    Table[Rotate["PlotPoints \[Rule] " <> ToString[i], \[Pi]/2], {i, 2, 18, 4}], 
    Table["Max Recursion \[Rule] " <> ToString[j], {j, 1, 5, 1}]

Grid of different PlotPoints and MaxRecursion values.

  • $\begingroup$ Great... Thank you Sir... This was the answer I was searching for. Thanks a lot $\endgroup$ – Hari Krishnan Jun 27 at 6:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.