5
$\begingroup$

This question already has an answer here:

I'm trying to draw a ListPlot where the x and y axis have the same scale.

My data is

{{100, 500}, {461/5, 473}, {548/5, 452}, {1459/10, 437}, {974/5, 428}, {250, 425}, 
 {1526/5, 428}, {3541/10, 437}, {1952/5, 452}, {2039/5, 473}, {400, 500}}

A simple ListPlot will result in:

Listplot no scale

where the x and y axis have a different scales.

I want them to force them to have the same scale. So far I've been able to achieve this only by explicitly setting PlotRange to the same value for x and y, and using AspectRation->1.

Example:

range := {Min[Flatten[x]], Max[Flatten[x]]}
ListPlot[x, PlotRange -> {range, range}, AspectRatio -> 1]

The result is:

List plot scaled

Questions:

  • Is there a Plot option to force the scale to be uniform? Do I always have to set the same range and AspectRatio to 1?

  • From the second image there is satisfying y ∈ [400, 500] and x < 100 with an x value that is lying outside of the drawing range. I thought by using the Min of all x and y this could not happen. What am I doing wrong?

$\endgroup$

marked as duplicate by Kuba, ciao, m_goldberg, ubpdqn, Öskå Jul 10 '14 at 10:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ AspectRatio -> Automatic. PlotRange in form {min, max} applies only to y axis. The x is Automatic, that's why the point is missing. $\endgroup$ – Kuba Jul 10 '14 at 7:49
1
$\begingroup$

As far as I know there is no other way besides setting the Options you describe, but there are many ways to make setting those Options more convenient. You can use SetOptions on ListPlot to make them the defaults, or you can use methods such as those shown here:

Regarding the BONUS: you must also set the AxesOrigin:

ListPlot[x,
 PlotRange -> {range, range},
 AspectRatio -> 1,
 AxesOrigin -> range[[1]]
]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ ListPlot[x, PlotRange -> All, AspectRatio -> Automatic] $\endgroup$ – Kuba Jul 10 '14 at 7:57
  • $\begingroup$ @Kuba I don't think that's what the OP wants, at least as I read the question. $\endgroup$ – Mr.Wizard Jul 10 '14 at 8:00
  • $\begingroup$ I see, I think it is, but my interpretations "sometimes" fail. The range used by OP is equal for both axes only to make aspectratio->1 work, that's what I think. $\endgroup$ – Kuba Jul 10 '14 at 8:01
  • $\begingroup$ @Kuba In retrospect I can see that interpretation now too, and I think you are probably correct. Alas, wasted effort. But I'll wait for the OP to confirm before I Close. $\endgroup$ – Mr.Wizard Jul 10 '14 at 8:03
  • $\begingroup$ Thanks for the answers. I don't specifically need the same range, I was just trying to have the same scale on the x and y axis. It seems that Kuba's first comment to this answer does the trick, although at a first glance it might not seem so, as the ticks on the y have a different resolution than the ticks on the x. $\endgroup$ – Marco83 Jul 10 '14 at 10:23
-2
$\begingroup$

Short Answer

     ListPlot[x, AspectRatio->1]

Long Answer

Don't change the default PlotRange of ListPlot !!!! The default PlotRange for ListPlot is Automatic, and this is exactly what you want.

Just change the default AspectRatio of ListPlot

Finding out the default setting for an specific option

   Options[ListPlot, AspectRatio]

   (*out*)
   {AspectRatio -> 1/GoldenRatio}


Comparing the output of

 ListPlot[x]

ListPlot[x]

ListPlot[x, AspectRatio -> 1]

ListPlot[x, AspectRatio->1


$\endgroup$
  • 2
    $\begingroup$ Thanks for the answer. However, this is not what I was looking for. If you look at your second plot, the scale on the x axis is not the same as the one on the y axis (x goes from ~0 to ~400, while y goes from ~430 to ~500 with the same length). $\endgroup$ – Marco83 Jul 11 '14 at 5:43

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