**Graphics****`****Graphics****`**

You can do most standard plots in two dimensions using the built-in functions Plot, ListPlot, and ParametricPlot. In certain situations you may want to display your data or function in a more specialized format, such as a bar chart or a log-log plot. The functions provided in this package may be used to produce such plots.

Log plots.

This loads the package.
In[1]:= **<< Graphics`Graphics`**

This gives a log-log plot of

.
In[2]:= **LogLogPlot[x^2, {x, 1, 3}]**

expdata is a list of exponential data with a random offset between -1 and 1.
In[3]:= **expdata = Table[**

{x, .92 10^(.94 x) + Random[Real,

{-1.0, 1.0}]}, {x, 0.2, 1.2, .1}]

Out[3]=

In a log plot, the exponential data appear roughly linear.
In[4]:= **LogListPlot[expdata]**

Polar plots.

This plots an ellipse and a limacon on the same graph.
In[5]:= **PolarPlot[{4/(2 + Cos[t]), 4 Cos[t] - 2},**

{t, 0, 2 Pi}]

Bar charts.

Graphics`Graphics` has functions for producing a variety of bar charts. Each bar chart function accepts a number of options controlling the style of the charts.

This gives a bar chart comparing two lists of numbers. Note that the lists need not have the same length.
In[6]:= **BarChart[{1, -3, 4, 5, 2, 3}, {3, 6, 4, 3}]**

Here the bars are stacked rather than placed side by side.
In[7]:= **StackedBarChart[{1, -3, 4, 5, 2, 3},**

{3, 6, 4, 3}]

A percentile bar chart scales the stacked bars so that each group has an absolute height of one.
In[8]:= **PercentileBarChart[{1, -3, 4, 5, 2, 3},**

{3, 6, 4, 3}]

In this chart the bars are explicitly positioned.
In[9]:= **GeneralizedBarChart[**

{{1, 3, .2}, {4, 9, 1}, {2.1, -6, .5}},

{{3, 5, .5}, {1.5, -2, 1}, {-.4, 2, .5}}]

Options for any of the bar chart functions.

The bar chart functions accept both special bar chart options and standard graphics options.

This percentile bar chart is created using bar chart options BarStyle and BarOrientation and graphics options Axes and Frame.
In[10]:= **PercentileBarChart[{1,3,-4,5,3.5,3},**

{-3,2,5,3},

BarStyle -> {RGBColor[0,1,0],

RGBColor[1,1,0]},

BarOrientation -> Horizontal,

Axes -> False, Frame -> True]

Options for BarChart and GeneralizedBarChart.

With the functions BarChart and GeneralizedBarChart, BarStyle specifies a function to be applied to the value of a bar, for the purpose of determining the bar's color.

Here the bars are colored according to a BarStyle function that gives one of three different values, depending on bar height.
In[11]:= **BarChart[{5, 3, 2, -2, 2, 6},**

BarStyle ->

(Which[

# > 4, RGBColor[0,1,0],

# < 0, RGBColor[1,0,0],

True, RGBColor[1,1,0]]&),

GridLines -> Automatic

]

Other bar chart options.

This is an example of using options to create a business chart. Note the use of standard options such as DefaultFont to change the font style.
In[12]:= **BarChart[{1, 3, 4, 5, 3.5, 3}, {3, 2, 5, 3},**

BarSpacing -> -.3, BarGroupSpacing -> .5,

BarStyle -> {GrayLevel[.6], Hue[0]},

BarEdgeStyle ->

{{Dashing[{.01}],Hue[0]},GrayLevel[0]},

BarLabels ->

{"Apr","May","Jun","Jul","Aug","Sep"},

PlotLabel -> "Projected and Current Profit,

Tourist Season",

DefaultFont -> {"Helvetica", 9}

]

Using PieChart.

PieChart generates a pie chart from a list of positive numbers. Several options are available for controlling the style of the pie.

Options for PieChart.

The PieStyle and PieLabels options are applied cyclically if there are not enough styles or labels to correspond with the number of wedges (in the same way that PlotStyle works). The PieLineStyle option applies equally to all lines in the chart. The PieExploded option moves designated wedges away from the center of the chart. The default is None, that is, no wedges are moved. One can specify a

number,distance

pair instead of just the index of a wedge to indicate how far out the wedge should be moved. The wedges are numbered counterclockwise, starting from the middle right.

This combines plots of a pie, an exploded pie, and a partially exploded pie.
In[13]:= **DisplayTogetherArray[**

PieChart[{.2,.3,.1}],

PieChart[{.2,.3,.1},

PieExploded->All],

PieChart[{.2,.3,.1},

PieExploded->{{3,.2}}]

]

A pie may be colored cyclically.
In[14]:= **PieChart[{.1, .2, .3, .4},**

PieStyle->{

GrayLevel[.3], GrayLevel[.8]}]

Pie wedges may be labeled.
In[15]:= **PieChart[{12, 21, 18},**

PieLabels -> {"Joe", "Helen", "Bob"},

PlotLabel -> "Sales"

]

Displaying plots together.

Often it is useful to generate several plots and show them together. The conventional way of doing this is to generate each plot separately with the option DisplayFunction->Identity and then combine the plots with Show. These functions automate that process. DisplayTogether can be handed any plotting commands that accept DisplayFunction->Identity as an option. The resulting plots must be able to be combined with Show for this function to be effective. DisplayTogether also accepts options that are suitable for the final output. DisplayTogetherArray accepts the same sort of inputs, but displays them in a GraphicsArray. The input plot commands should be entered in an array whose structure matches that of the desired output array. DisplayTogetherArray accepts options suitable for GraphicsArray.

This is a set of random data following a square law.
In[16]:= **data = Table[{n/15, (n/15)^2 + 2 + Random[Real,{-.3,.3}]},**

{n, 15}];

This fits a linear combination of , , and

to the data.
In[17]:= **fit = Fit[data, {1, x, x^2}, x]**

Out[17]=

This fits a linear combination of and

to the data.
In[18]:= **altfit = Fit[data, {1,x^3}, x]**

Out[18]=

Here the two fitted curves are combined with a plot of the data.
In[19]:= **DisplayTogether[**

Plot[altfit, {x,0,1},

PlotStyle -> Hue[.6]],

ListPlot[data,

PlotStyle -> {Hue[0],

PointSize[.03]}],

Plot[fit, {x,0,1},

PlotStyle -> {GrayLevel[0],

Dashing[{.03}]}]

]

The pie charts previously combined in a side by side arrangement are combined here in a different array arrangement. The structure of the array in which the chart commands are input to DisplayTogetherArray is reflected in the output arrangement of the charts.
In[20]:= **DisplayTogetherArray[**

{{PieChart[{.2,.3,.1}],

PieChart[{.2,.3,.1},

PieExploded -> All]},

{PieChart[{.2,.3,.1},

PieExploded->{{3,.2}}]}

}

]

Variations on ListPlot.

Graphics`Graphics also implements a number of ListPlot variants. These include some techniques for labeling plots of data, and a function to place error bars on data. Alternatives to these plots and other modifications to the shape of points used in plots of data can be found in the package Graphics`MultipleListPlot`.

Here the "data" are defined using the digits of Pi.
In[21]:= **data = First[RealDigits[N[Pi]]]**

Out[21]=

The digits of Pi are plotted using the integers

as plotting symbols.
In[22]:= **TextListPlot[data]**

This gives the same plot, except that the integers

serve as labels instead of plotting symbols.
In[23]:= **LabeledListPlot[data]**

This creates a new list with the magnitude of the "error", , appended to each data pair in expdata

.
In[24]:= **erexpdata = Map[Append[#, 1.0]&, expdata]**

Out[24]=

Here is a plot of the data in expdata with error bars.
In[25]:= **errorp = ErrorListPlot[erexpdata]**

See the package Graphics`MultipleListPlot` for another way of plotting error bars that allows multiple data sets and lines between the points, among other features.