3
$\begingroup$

Mathematica help file says:

"With ImageSize->{w,h} an object will always be drawn in a $w\times h$ region, and will be sized to fit in the region. "

However:

enter image description here

Doesn't look like "and will be sized to fit in the region" is working. Am I thinking incorrectly here?

Using Version 10.0.

$\endgroup$
6
$\begingroup$

First, here is a trick to see the actual space used by the plot:

Grid[{{Plot[Sqrt[100 - x^2], {x, 0, 100}, PlotRange -> Automatic, 
      ImageSize -> {250, 100}]}}, Frame -> All]

Mathematica graphics

Grid[{{Plot[Sqrt[100 - x^2], {x, 0, 100}, PlotRange -> Automatic, 
    ImageSize -> {500, 100}]}}, Frame -> All]

Mathematica graphics

So you can see that it did actually use more space (width). Now if you want to widen your plot, this is something else. You can use Aspect ratio for this.

Grid[{{Plot[Sqrt[100 - x^2], {x, 0, 100}, PlotRange -> Automatic, 
   ImageSize -> {500, 100}, AspectRatio -> .2]}}, Frame -> All]

Mathematica graphics

But this does not look too good. ps. (You can also use Framed@Plot[...] to see the actual space used instead of Grid as above)

$\endgroup$
  • 2
    $\begingroup$ Nice answer. Looks like this works as well: Framed@Plot[Sqrt[100 - x^2], {x, 0, 100}, PlotRange -> Automatic, ImageSize -> {500, 100}, AspectRatio -> Full] $\endgroup$ – David Nov 10 '14 at 2:41
  • 1
    $\begingroup$ It is worth to mention that AspectRation should be exactly equal to 100/500, i.e. h/w where h and w are from ImageSize->{w,h}. $\endgroup$ – Alexey Popkov Nov 10 '14 at 3:08
  • $\begingroup$ @Alexey Popkov It is a useful point. Alexey, why would not you formulate this as a regular answer? $\endgroup$ – Alexei Boulbitch Nov 10 '14 at 9:24
  • 1
    $\begingroup$ @David Be careful of that option! It can produce weird problems: (19656) $\endgroup$ – Mr.Wizard Nov 10 '14 at 11:55
  • $\begingroup$ @AlexeiBoulbitch Done. $\endgroup$ – Alexey Popkov Nov 10 '14 at 15:25
3
$\begingroup$

By default Plot has AspectRatio -> 1/GoldenRatio which is a definite value:

1./GoldenRatio
0.6180339887498948

According to the Documentation page for ImageSize (emphasis mine),

  • With ImageSize->{w,h} an object will always be drawn in a $w×h$ region, and will be sized to fit in the region.

  • If the object has a definite aspect ratio that is not $h/w$, then space will be left around it.

From the above follows that ImageSize does not change AspectRatio when the latter has a definite value and if you want the plot to fit the ImageSize you should explicitly specify AspectRatio -> h/w where h and w are taken from ImageSize -> {w, h}:

Grid[{{Plot[Sqrt[100 - x^2], {x, 0, 100}, PlotRange -> Automatic, 
    AspectRatio -> 1/5, ImageSize -> {500, 100}]}}, Frame -> All]

plot

$\endgroup$

Your Answer

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

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