Two-Dimensional Graphics Elements
| Point[{x,y}] | point at position x, y |
| Line[{{x1,y1},{x2,y2},...}] | line through the points {x1, y1}, {x2, y2}, ... |
| Rectangle[{xmin,ymin},{xmax,ymax}] | filled rectangle |
| Polygon[{{x1,y1},{x2,y2},...}] | filled polygon with the specified list of corners |
| Circle[{x,y},r] | circle with radius r centered at x, y |
| Disk[{x,y},r] | filled disk with radius r centered at x, y |
| Raster[{{a11,a12,...},{a21,...},...}] | rectangular array of gray levels between 0 and 1 |
| Text[expr,{x,y}] | the text of expr, centered at x, y (see "Graphics Primitives for Text") |
Basic two-dimensional graphics elements.
Here is a line primitive.
| Out[1]= |  |
|
This shows the line as a two-dimensional graphics object.
| Out[2]= |  |
|
This redisplays the line, with axes added.
| Out[3]= |  |
|
You can combine graphics objects that you have created explicitly from graphics primitives with ones that are produced by functions like
Plot.
This produces an ordinary Mathematica plot.
| Out[4]= |  |
|
This combines the plot with the sawtooth picture made above.
| Out[5]= |  |
|
You can combine different graphical elements simply by giving them in a list. In two-dimensional graphics,
Mathematica will render the elements in exactly the order you give them. Later elements are therefore effectively drawn on top of earlier ones.
Here are two blue Rectangle graphics elements.
| Out[6]= |  |
|
This draws the rectangles on top of the line that was defined above.
| Out[7]= |  |
|
The
Polygon graphics primitive takes a list of
x,
y coordinates, corresponding to the corners of a polygon.
Mathematica joins the last corner with the first one, and then fills the resulting area.
Here are the coordinates of the corners of a regular pentagon.
| Out[8]= |  |
|
This displays the pentagon. With the default choice of aspect ratio, the pentagon looks somewhat squashed.
| Out[9]= |  |
|
| Point[{pt1,pt2,...}] | a multipoint consisting of points at pt1, pt2, ... |
| Line[{line1,line2,...}] | a multiline consisting of lines line1, line2, ... |
| Polygon[{poly1,poly2,...}] | a multipolygon consisting of polygons poly1, poly2, ... |
Primitives which can take multiple elements.
A large number of points can be represented by putting a list of coordinates inside of a single
Point primitive. Similarly, a large number of lines or polygons can be represented as a list of coordinate lists. This representation is efficient and can generally be rendered more quickly by the
Mathematica front end. Graphics directives such as
RGBColor apply uniformly to the entire set of primitives.
This creates a multipolygon based upon the set of coordinates defined previously.
| Out[10]= |  |
|
Here is a multipoint which is colored blue.
| Out[11]= |  |
|
| Circle[{x,y},r] | a circle with radius r centered at the point {x, y} |
| Circle[{x,y},{rx,ry}] | an ellipse with semi-axes rx and ry |
| Circle[{x,y},r,{theta1,theta2}] | a circular arc |
| Circle[{x,y},{rx,ry},{theta1,theta2}] | an elliptical arc |
| Disk[{x,y},r], etc. | filled disks |
Circles and disks.
This shows two circles with radius 2.
| Out[12]= |  |
|
This shows a sequence of disks with progressively larger semi-axes in the x direction, and progressively smaller ones in the y direction.
| Out[13]= |  |
|
Mathematica allows you to generate arcs of circles, and segments of ellipses. In both cases, the objects are specified by starting and finishing angles. The angles are measured counterclockwise in radians with zero corresponding to the positive
x direction.
This draws a 140 wedge centered at the origin.
| Out[14]= |  |
|
| Raster[{{a11,a12,...},{a21, ... }, ... }] | array of gray levels between 0 and 1 |
| Raster[{{{a11,o11},...},...}] | array of gray levels with opacity between 0 and 1 |
| Raster[{{{r11,g11,b11},...},...}] | array of rgb values between 0 and 1 |
| Raster[{{{r11,g11,b11,o11},...},...}] | array of rgb values with opacity between 0 and 1 |
| Raster[array,{{xmin,ymin},{xmax,ymax}},{zmin,zmax}] | array of gray levels between zmin and zmax drawn in the rectangle defined by {xmin, ymin} and {xmax, ymax} |
Raster-based graphics elements.
Here is a 4×4 array of values between 0 and 1.
| Out[15]= |  |
|
This uses the array of values as gray levels in a raster.
| Out[16]= |  |
|
This shows two overlapping copies of the raster.
| Out[17]= |  |
|
| Out[18]= |  |
|