0
$\begingroup$

I want to draw a line.

Graphics[{Line[{{0, 0}, {10, 0}}]}]

Out

enter image description here

Note that changing the end point does not affect the displayed line.

Graphics[{Line[{{0, 0}, {20, 0}}]}]

Out

enter image description here

But I want to draw a longer line. How to do it?

$\endgroup$
2
  • 2
    $\begingroup$ Add Frame -> True at the end of Graphics to see what happens. Look up ImageSize and AspectRatio to control the graphics size and shape. $\endgroup$
    – Szabolcs
    Commented May 6, 2017 at 20:19
  • $\begingroup$ Manipulate[ Graphics[{Line[{{0, 0}, {x, 0}}]}, ImageSize -> 72*x], {{x, 1}, 1, 5, Appearance -> "Labeled"}] $\endgroup$
    – Bob Hanlon
    Commented May 6, 2017 at 21:03

2 Answers 2

1
$\begingroup$

While the scale answer is technically correct, what you really are trying to do, is to prevent the background from continually resizing to accommodate graphical contents.

The option you want is PlotRange->{{Xmin,Xmax},{Ymin,Ymax}} (optionally, Zmin,Zmax for 3D graphics. Another 2 options which affect the output size are ImageSize and AspectRatio. One scales the whole graphic, another "squishes" the graphic to accommodate a given Y:X ratio. So AspectRatio->2 would give you a vertical rectangle, and AspectRatio->1/2 - a horizontal one, while AspectRatio->1 is a perfect square.

Try this:

Graphics[{
          (* your graphics directives here *)
         }, PlotRange->{{0,50},{0,50}}, AspectRatio->1, ImageSize->800]

Enjoy!

$\endgroup$
0
$\begingroup$

If you have to draw only one line, then it will be automatically scaled as in your example. You can make this line bigger by clicking on the image and make the borders bigger with the mouse...

If you draw two lines then you will see the correct result (ratio)

Graphics[{Scale[Line[{{0, 0}, {10, 0}}], 3], Line[{{0, 1}, {10, 1}}]}]

in the example above the first line can be scaled

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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