Mathematica : Draw a simple line, make into image

Click For Summary
SUMMARY

This discussion focuses on creating an image in Mathematica using the Graphics function to draw lines. The user initially attempted to display lines with specific coordinates but encountered issues with alignment. The solution involved wrapping the Graphics function in a Show[] command and utilizing the PlotRange option to ensure the lines appeared correctly on the left side of the image. The final code provided was: Show[Graphics[Line[{{{10, 0}, {40, 100}}, {{20, 0}, {80, 100}}}], ImageSize -> {400, 100}, AlignmentPoint -> {Left, Bottom}], PlotRange -> {{0, 400}, {0, 100}}].

PREREQUISITES
  • Familiarity with Mathematica syntax and functions
  • Understanding of the Graphics and Show functions in Mathematica
  • Knowledge of coordinate systems and plotting in 2D graphics
  • Experience with the PlotRange option in Mathematica
NEXT STEPS
  • Explore advanced options in the Graphics function in Mathematica
  • Learn about customizing PlotRange for different graphic elements
  • Investigate the use of AlignmentPoint for positioning graphics
  • Study the integration of multiple graphical elements in Mathematica
USEFUL FOR

This discussion is beneficial for Mathematica users, graphic designers, and educators looking to enhance their skills in creating and manipulating graphical representations in Mathematica.

Hepth
Science Advisor
Gold Member
Messages
458
Reaction score
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
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.
 
PlotRange worked! Thanks a million. Now to post another question...
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
Replies
2
Views
2K
  • · Replies 0 ·
Replies
0
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 24 ·
Replies
24
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K