Graphics Introduction Examples

Two-dimensional graphics can be created using the function Graphics and a list of graphics primitives. For three-dimensional graphics see the following section. The following primitives are available:


Circle[{x, y}, r]

draws a circle.

Disk[{x, y}, r]

draws a filled disk.

Rectangle[{$x_1$, $y_1$}, {$x_2$, $y_2$}]

draws a filled rectangle.

Polygon[{{$x_1$, $y_1$}, {$x_2$, $y_2$}, ...}]

draws a filled polygon.

Line[{{$x_1$, $y_1$}, {$x_2$, $y_2$}, ...}]

draws a line.

Text[text, {x, y}]

draws text in a graphics.

Colors can be added in the list of graphics primitives to change the drawing color. The following ways to specify colors are supported:


RGBColor[r, g, b]

specifies a color using red, green, and blue.

CMYKColor[c, m, y, k]

specifies a color using cyan, magenta, yellow, and black.

Hue[h, s, b]

specifies a color using hue, saturation, and brightness.

GrayLevel[l]

specifies a color using a gray level.

All components range from 0 to 1. Each color function can be supplied with an additional argument specifying the desired opacity (“alpha”) of the color. There are many predefined colors, such as Black, White, Red, Green, Blue, etc.

Table of hues:

Colors can be mixed and altered using the following functions:


Blend[{$color1$, $color2$}, ratio]

mixes $color1$ and $color2$ with ratio, where a ratio of 0 returns $color1$ and a ratio of 1 returns $color2$.

Lighter[color]

makes color lighter (mixes it with White).

Darker[color]

makes color darker (mixes it with Black).

Graphics produces a GraphicsBox:

Functions and Patterns
Plotting Introduction Examples