Mathematica : Draw a simple line, make into image

In summary, the conversation discussed creating an image in Mathematica using a set of lines and specifying the image size and alignment point. The solution was to wrap the Graphics function in a Show function and use the PlotRange option to position the lines on the left side of the image.
  • #1
Hepth
Gold Member
464
40
I wish to create, in Mathematica, an image.

I have a set of lines, for the sake of a test, let's use:

{{10,0},{40,100}}
{{20,0},{80,100}}

Now I want my image to be 400x100 pixels, and the lines to appear as if their coordinates are those of the points in the image. If I do:

Graphics[Line[{{{10, 0}, {40, 100}}, {{20, 0}, {80, 100}}}],
ImageSize -> {400, 100}, AlignmentPoint -> {Left, Bottom}]

It doesn't work. Any help? The lines should be on the left side of the picture.
 
Physics news on Phys.org
  • #2
Wrap a Show[] around your Graphics[]

In[1]:= Show[Graphics[Line[{{{10, 0}, {40, 100}}, {{20, 0}, {80, 100}}}], ImageSize -> {400, 100}, AlignmentPoint -> {Left, Bottom}]]

Out[1]= ...ImageSnipped...

But this doesn't address your "The lines should be on the left side of the picture."

Maybe what you want is to specify the PlotRange option, something like this

In[2]:= Show[Graphics[Line[{{{10, 0}, {40, 100}}, {{20, 0}, {80, 100}}}], ImageSize -> {400, 100}, AlignmentPoint -> {Left, Bottom}], PlotRange -> {{0, 400}, {0, 100}}]

Out[2]= ...ImageSnipped...

But there are lots of options you may need to explore to get a graphic to be just the way you want.
 
  • #3
PlotRange worked! Thanks a million. Now to post another question...
 

Related to Mathematica : Draw a simple line, make into image

1. How do I draw a simple line in Mathematica?

To draw a simple line in Mathematica, you can use the Line function. First, specify the starting and ending points of the line, then use Graphics to display the line on a plot. For example, Graphics[Line[{{0,0}, {1,1}}]] will draw a diagonal line from (0,0) to (1,1).

2. Can I change the color and thickness of the line?

Yes, you can use the Graphics options to change the color and thickness of the line. For color, you can use RGBColor or Hue to specify the desired color. For thickness, you can use the Thickness option. For example, Graphics[{Thickness[0.02], RGBColor[0,0,1], Line[{{0,0}, {1,1}}]}] will draw a blue line with a thickness of 0.02.

3. How can I add multiple lines to the same plot?

To add multiple lines to the same plot, you can use the Graphics function with a list of Line objects. For example, Graphics[{Line[{{0,0}, {1,1}}], Line[{{0,1}, {1,0}}]}] will draw two diagonal lines crossing each other.

4. Can I save the line as an image file?

Yes, you can use the Export function to save the line as an image file. Specify the desired file format and file name in the function. For example, Export["line.png", Graphics[Line[{{0,0}, {1,1}}]]] will save the line as a PNG file named "line".

5. How can I rotate or resize the line?

To rotate or resize the line, you can use the Rotate and Scale functions respectively. These functions take in the object to be transformed, the angle or factor of transformation, and the center point of rotation or scaling. For example, Rotate[Graphics[Line[{{0,0}, {1,1}}]], Pi/4, {0,0}] will rotate the line by 45 degrees counterclockwise around the point (0,0).

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • Programming and Computer Science
Replies
4
Views
4K
  • Calculus and Beyond Homework Help
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
4K
  • Programming and Computer Science
Replies
24
Views
1K
  • General Discussion
Replies
22
Views
2K
  • Mechanical Engineering
Replies
20
Views
2K
  • Calculus and Beyond Homework Help
Replies
1
Views
1K
Back
Top