Graphics and Plotting

Mathematica has a large number of built-in graphics programs for plotting and exploring mathematics graphically and for plotting a visualizing data.  Graphs and plots are effective ways of conveying complex information.  It is important to learn how to create and manipulate plots and graphics.  Mathematica is very rich in its graphical functions—we will explore only a subset of all its capabilities.  We can get an idea of how many plotting routines are available by
using a wildcard:

?*Plot*

This is much less than are available in the standard packages; these will be discussed later, but here is an example of loading the Graphics Packages:

<< Graphics`

?*Plot*

While Mathematica has a large number of plotting routines, no one program does everything we need.  It is useful to export numbers and graphics from Mathematica and operate on them individually or with other specialized programs.  The number of different creative graphical solutions available grows geometrically with the number of different graphical tools that are mastered.
    
    Here, we will just produce a number of examples of plots and graphics... (Note, I use a file "init.m" to set some options.  Your plots may look different from what we see in lecture. If you want to use my init.m you can download it from here. Where to locate your init.m file depends on the operating system you are using, check out init.m in the Master Index in the Help Browser.

Two-Dimensional Graphics

Plot, ParametricPlot, LogPlot, etc

Plot[Sin[x]/x, {x, -5 Pi, 5  Pi}]

Options[Plot]

Plot[Sin[x]/x, {x, -5 Pi, 5  Pi}, 
      PlotRange -> {-0.25, 1.25}]

\(Plot[Sin[x]/x, {x, \(-5\) Pi, 5  Pi}, 
      PlotRange -> {\(-0.25\), 1.25}, 
      AxesLabel -> {"x", \*""\!\(\(Sin \((x)\)\)\/x\)""}]\)

Plot[{Sin[x]/x, Tan[x]/x}, {x, -5 Pi, 5  Pi}, 
      PlotRange -> {-0.25, 1.25}]

Plot[{Sin[x]/x, Tan[x]/x}, {x, -5 Pi, 5  Pi}, 
      PlotRange -> {-0.25, 
          1.25}, 
PlotStyle -> {{Thickness[0.01], 
            Hue[1]}, {Thickness[0.005], Hue[2/3]}}]

LuckyClover[t_  ,  
        n_]  :=  (1/(n + 1)) {Cos[(n + 1) t  -  
                Pi/4]  -  (n + 1) Cos[t  -  Pi/4],  
          Sin[(n + 1) t  -  Pi/4]  -  (n + 1) 
              Sin[t  -  Pi/4]}

ParametricPlot[LuckyClover[t, 4], {t, 0,  2 Pi}]

ParametricPlot[LuckyClover[t, 4], {t, 0,  2 Pi},  
      AspectRatio -> 1]

ParametricPlot[Table[LuckyClover[t, i], {i, 2, 7}], {t, 0,  2 Pi},  
      AspectRatio -> 1]

ParametricPlot[
      Evaluate[Table[LuckyClover[t, i], {i, 2, 7}]], {t, 0,  2 Pi},  
      AspectRatio -> 1]

ParametricPlot[
      Evaluate[Table[LuckyClover[t, i], {i, 2, 7}]], {t, 0,  2 Pi},  
      AspectRatio -> 1, 
      PlotStyle -> 
        Table[{Thickness[0.005], Hue[(2/3)*(i - 2)/5]}, {i, 2, 
            7}]]

<< Miscellaneous`PhysicalConstants`

BoltzmannConstant
ElectronCharge

Kelvin[TempCelcius_ ]  :=  273.15  +  TempCelcius

Arrhenius[EnergyEV_,  TempCelcius_ ]  :=  
      Exp[-(EnergyEV*Joule*ElectronCharge)/(Kelvin[TempCelcius]*
              BoltzmannConstant*Kelvin*Coulomb)]

Arrhenius[e, t]

ParametricPlot[{1/Kelvin[T], Log[Arrhenius[1.0, T]]}, {T, 0, 
        1000}]

arrhenplot  = 
      ParametricPlot[
        Evaluate[
          Table[{1/Kelvin[T], Log[Arrhenius[ev, T]]}, {ev, 1, 5, 
              1}]], {T, -200, 1000}, 
        PlotStyle -> 
          Table[{Thickness[0.005], Hue[(2/3)*(5 - i)/4]}, {i, 1, 5, 
              1}]]

Show[arrhenplot, 
      Ticks -> {Table[{1/Kelvin[T], 
              StringJoin["1/", ToString[T]]}, {T, -200, 500, 
              100
}], Automatic}]

BankAccount[InitialInvestment_ ,  AnnualInterest_,  
        NYears_ ]  :=  
      InitialInvestment*(1  +  AnnualInterest/100)^NYears

Plot[BankAccount[100, 8.5, t], {t, 0, 50}]

<< Graphics`

LogPlot[BankAccount[100, 8.5, t], {t, 0, 50}]

Plotting Data

ListPlot, PieChart, Histogram, Barchart, etc

<< Miscellaneous`ChemicalElements`

Elements

e190  =  Elements[[Table[i, {i, 1, 90}]]]

mps  =  Map[MeltingPoint[#] &, e190] /. Kelvin -> 1

ListPlot[mps]

ListPlot[mps, PlotJoined -> True]

Dens  =  
      Map[Density[#] &, e190] /. {Kilogram -> 1,  
          Meter -> 1}

dmdata  =  Transpose[{Dens, mps}]

ListPlot[dmdata]

ListPlot[dmdata, PlotJoined -> True]

Three-Dimensional Graphics

Plot3D, ContourPlot, DensityPlot, etc

EPot[x_,  y_ ,  z_ ,  xo_ ,  yo_]  :=  
      (1/(Sqrt[(x - xo)^2  +  (y - yo)^2  +  z^2]))

SheetOLatticeCharge[x_,  y_ ,  z_]  :=  
      Sum[EPot[x, y, z, xo, yo], {xo, -5, 5}, {yo, -5, 5}]

Plot3D[
      Evaluate[SheetOLatticeCharge[x, y, 0.25]], {x, -6, 6}, {y, -6, 
        6}]

theplot  = 
      Plot3D[Evaluate[SheetOLatticeCharge[x, y, 0.25]], {x, -6, 
          6}, {y, -6, 6}, PlotPoints -> 120]

Show[theplot, ViewPoint -> {0, -5, 2}]

theconplot  = 
      ContourPlot[
        Evaluate[SheetOLatticeCharge[x, y, 0.25]], {x, -6, 
          6}, {y, -6, 6}, PlotPoints -> 120]

theconplot  = 
      ContourPlot[
        Evaluate[SheetOLatticeCharge[x, y, 0.25]], {x, -4, 
          4}, {y, -4, 4}, PlotPoints -> 120, 
        ColorFunction -> Hue, Contours -> 24]

thedenplot  = 
      DensityPlot[
        Evaluate[SheetOLatticeCharge[x, y, 0.25]], {x, -4, 
          4}, {y, -4, 4}, PlotPoints -> 120, 
        ColorFunction -> (Hue[1 - #*0.66] &)]

Show[thedenplot, Mesh -> False]

Graphics Primitives

Show[Graphics[Circle[{2, 2}, 1.5]]]

Show[Graphics[Circle[{2, 2}, 1.5]], Axes -> True]

Show[Graphics[Circle[{2, 2}, 1.5]], Axes -> True, 
      AxesOrigin -> {0, 0}, AspectRatio -> 1]

cosplot  =  Plot[Cos[x], {x, 0, 4  Pi}]

Show[cosplot, Graphics[Text["One Wavelength", {2 Pi, 1.1}]], 
      Graphics[Text["Two Wavelengths", {4 Pi, 1.1}]], 
      PlotRange -> All]

Show[cosplot, Graphics[Text["One Wavelength", {2 Pi, 1.1}]], 
      Graphics[Text["Two Wavelengths", {4 Pi, 1.1}]], 
      PlotRange -> All]

randomwalk[0]  =  {0, {0, 0}}

randomwalk[0][[2]]

randomwalk[
        nstep_Integer?Positive]  :=  randomwalk[
          nstep] = {nstep, randomwalk[
                nstep - 1][[2]]  +  
Random[
                Real, {0, 0.5}]*{Cos[theta  = 2 Pi Random[]], 
                Sin[theta]}}

randomwalk[4]

Show[
      Table[Graphics[
          Text[ToString[randomwalk[i][[1]]], randomwalk[
                i][[2]]]], {i, 0, 100}], PlotRange -> All, 
      AspectRatio -> 1, AxesOrigin -> {0, 0}]

Show[
Table[
        Graphics[
          Text[ToString[randomwalk[i][[1]]], randomwalk[
                i][[2]]]], {i, 0, 50}], 
Table[
        Graphics[
          Line[{randomwalk[j - 1][[2]], randomwalk[
                  j][[2]]}]], {j, 1, 
          50}], 
PlotRange -> All, 
      AspectRatio -> 1, AxesOrigin -> {0, 0}]

wulffline[{x_, y_}, wulfflength_]  =  
      Module[{theta, wulffhalflength = wulfflength*0.5, x1, x2, y1, y2}, 
        theta = ArcTan[x, y]; 
 
        x1  =  x  +  
            wulffhalflength*Cos[theta  +  Pi/2]; 
 
        x2 =   x  +  
            wulffhalflength*Cos[theta  -  Pi/2]; 
 
        y1  =  y  +  
            wulffhalflength*Sin[theta  +  Pi/2]; 
y2 =  
          y  +  wulffhalflength*
              Sin[theta  -  Pi/2]; 
Graphics[
          Line[{{x1, y1}, {x2, y2}}]]
]

gammaplot[theta_ ,  anisotropy_ ,  
        nfold_]  :=  {Cos[theta] +  anisotropy*Cos[(nfold + 1)*theta], 
        Sin[theta]  +  anisotropy*Sin[(nfold + 1)*theta]}

GammaPlot  =  
      ParametricPlot[gammaplot[t, 0.1, 4], {t, 0, 2 Pi}, 
        AspectRatio -> 1, 
        PlotStyle -> {{Thickness[0.005], RGBColor[1, 0, 0]}}]

Show[
      Table[wulffline[gammaplot[t, 0.1, 4], 2], {t, 0,  2 Pi,  
          2 Pi/100}], GammaPlot, AspectRatio -> 1]