Graphics and Plotting

Mathematica has a large number of built-in graphics programs for plotting and exploring mathematics graphically and for plotting and 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 just a small subset of all its capabilities.  We can get an idea of how many plotting routines are available byusing a wildcard:

In[116]:=

? *Plot*

System`
ArrayPlot ListContourPlot ListPlot3D ParametricPlot3D Plot3Matrix PlotLabel PlotRegion
ContourPlot ListDensityPlot MaxPlotPoints Plot PlotDivision PlotPoints PlotStyle
DensityPlot ListPlot ParametricPlot Plot3D PlotJoined PlotRange
Global`
GammaPlot
Graphics`Animation`
MovieContourPlot MovieDensityPlot MovieParametricPlot MoviePlot MoviePlot3D
Graphics`ContourPlot3D`
ContourPlot3D ListContourPlot3D
Graphics`FilledPlot`
FilledListPlot FilledPlot ListFilledPlot
Graphics`Graphics`
ErrorListPlot LinearLogListPlot ListAndCurvePlot LogLinearPlot LogLogListPlot LogPlot PolarPlot ScaledPlot
LabeledListPlot LinearLogPlot LogLinearListPlot LogListPlot LogLogPlot PolarListPlot ScaledListPlot TextListPlot
Graphics`Graphics3D`
ListShadowPlot3D ListSurfacePlot3D ScatterPlot3D ShadowPlot3D
Graphics`ImplicitPlot`
ImplicitPlot
Graphics`InequalityGraphics`
ComplexInequalityPlot InequalityPlot InequalityPlot3D
Graphics`Legend`
PlotLegend
Graphics`MultipleListPlot`
MultipleListPlot PlotSymbol
Graphics`ParametricPlot3D`
CylindricalPlot3D PointParametricPlot3D SphericalPlot3D
Graphics`PlotField`
ListPlotVectorField PlotGradientField PlotHamiltonianField PlotPolyaField PlotVectorField
Graphics`PlotField3D`
ListPlotVectorField3D PlotGradientField3D PlotVectorField3D

This is much less than are available in the standard packages; these will be discussed later, but here's what becomes available after loading the Graphics Packages:

In[117]:=

<< Graphics`

While Mathematica has a large number of plotting routines, no one program does everything we need.  It can be 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

In[119]:=

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

[Graphics:HTMLFiles/Lecture-05_1.gif]

Out[119]=

Graphics

In[120]:=

Options [ Plot ]

Out[120]=

{ AspectRatio 1 GoldenRatio , Axes Automatic , AxesLabel None , AxesOrigin Automatic , AxesStyle { Thickness [ 0.01 ] } , Background Automatic , ColorOutput Automatic , Compiled True , DefaultColor Automatic , DefaultFont $DefaultFont , DisplayFunction $DisplayFunction , Epilog { } , FormatType $FormatType , Frame False , FrameLabel None , FrameStyle Automatic , FrameTicks Automatic , GridLines None , ImageSize Automatic , MaxBend 10. , PlotDivision 30. , PlotLabel None , PlotPoints 25 , PlotRange Automatic , PlotRegion Automatic , PlotStyle { { Thickness [ 0.0075 ] , PointSize [ 0.01 ] } } , Prolog { } , RotateLabel True , TextStyle $TextStyle , Ticks Automatic }

In[121]:=

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

[Graphics:HTMLFiles/Lecture-05_2.gif]

Out[121]=

Graphics

In[122]:=

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

[Graphics:HTMLFiles/Lecture-05_3.gif]

Out[122]=

Graphics

In[123]:=

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

[Graphics:HTMLFiles/Lecture-05_4.gif]

Out[123]=

Graphics

In[124]:=

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 ] } } ]

[Graphics:HTMLFiles/Lecture-05_5.gif]

Out[124]=

Graphics

ParametricPlot produces a 2-D graph as a function of a single parameter, e.g. t. The cartesian coordinates, e.g. x and y, are specified as functions x(t) and y(t). Thus, a continuous variation of the single parameter t will trace out a trajectory in the x-yˆplane.

In[125]:=

? ParametricPlot

ParametricPlot[{fx, fy}, {u, umin, umax}] produces a parametric plot of a curve with x and y coordinates fx and fy generated as a function of u. ParametricPlot[{{fx, fy}, {gx, gy}, ... }, {u, umin, umax}] plots several parametric curves. More…

In[126]:=

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 ] }

In[127]:=

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

[Graphics:HTMLFiles/Lecture-05_6.gif]

Out[127]=

Graphics

In[128]:=

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

[Graphics:HTMLFiles/Lecture-05_7.gif]

Out[128]=

Graphics

The next statement attempts to use the Table function to produce a list of six LuckyClover functions and then make one parametric plot of all of them.

In[129]:=

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

ParametricPlot :: pptr : Table [ LuckyClover [ t , i ] , { i , 2 , 7 } ] does not evaluate to a pair of real numbers at t = 2.617993877991494 × 10 - 7 . More… "\\!\\(Table[\\(\\(\\(\\(LuckyClover[\\(\\(t, i\\)\\)]\\)\\), \\(\\({i, 2, 7}\\)\\)\\)\\)]\\) does not evaluate to a pair of real numbers at \\!\\(t\\) = \\!\\(2.617993877991494`*^-7\\). \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"ParametricPlot::pptr\\\"]\\)"

ParametricPlot :: pptr : Table [ LuckyClover [ t , i ] , { i , 2 , 7 } ] does not evaluate to a pair of real numbers at t = 0.25488992540742256 . More… "\\!\\(Table[\\(\\(\\(\\(LuckyClover[\\(\\(t, i\\)\\)]\\)\\), \\(\\({i, 2, 7}\\)\\)\\)\\)]\\) does not evaluate to a pair of real numbers at \\!\\(t\\) = \\!\\(0.25488992540742256`\\). \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"ParametricPlot::pptr\\\"]\\)"

ParametricPlot :: pptr : Table [ LuckyClover [ t , i ] , { i , 2 , 7 } ] does not evaluate to a pair of real numbers at t = 0.5328694051959509 . More… "\\!\\(Table[\\(\\(\\(\\(LuckyClover[\\(\\(t, i\\)\\)]\\)\\), \\(\\({i, 2, 7}\\)\\)\\)\\)]\\) does not evaluate to a pair of real numbers at \\!\\(t\\) = \\!\\(0.5328694051959509`\\). \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"ParametricPlot::pptr\\\"]\\)"

General :: stop : Further output of ParametricPlot :: pptr will be suppressed during this calculation. More… "Further output of \\!\\(ParametricPlot :: \\\"pptr\\\"\\) will be suppressed during this calculation. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"General::stop\\\"]\\)"

[Graphics:HTMLFiles/Lecture-05_8.gif]

Out[129]=

Graphics

It is necessary to use the Evaluate command to get this to work.

In[130]:=

? Evaluate

Evaluate[expr] causes expr to be evaluated even if it appears as the argument of a function whose attributes specify that it should be held unevaluated. More…

In[131]:=

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

[Graphics:HTMLFiles/Lecture-05_9.gif]

Out[131]=

Graphics

In[132]:=

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 } ] ]

[Graphics:HTMLFiles/Lecture-05_10.gif]

Out[132]=

Graphics

In[133]:=

<< Miscellaneous`PhysicalConstants`

In[134]:=

BoltzmannConstant

ElectronCharge

SpeedOfLight

Out[134]=

1.3806503 × 10 - 23 Joule Kelvin

Out[135]=

1.602176462 × 10 - 19 Coulomb

Out[136]=

299792458 Meter Second

In[137]:=

Kelvin [ TempCelcius_ ] := 273.15 + TempCelcius

In[138]:=

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

In[139]:=

Arrhenius [ e , t ]

Out[139]=

- 11604.505949116876 e 273.15 + t

In[140]:=

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

[Graphics:HTMLFiles/Lecture-05_14.gif]

Out[140]=

Graphics

In[141]:=

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 } ] ]

[Graphics:HTMLFiles/Lecture-05_15.gif]

Out[141]=

Graphics

In[142]:=

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

[Graphics:HTMLFiles/Lecture-05_16.gif]

Out[142]=

Graphics

In[143]:=

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

In[144]:=

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

[Graphics:HTMLFiles/Lecture-05_17.gif]

Out[144]=

Graphics

In[145]:=

<< Graphics`

In[146]:=

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

[Graphics:HTMLFiles/Lecture-05_18.gif]

Out[146]=

Graphics

Plotting Data

ListPlot, PieChart, Histogram, Barchart, etc

In[147]:=

<< Miscellaneous`ChemicalElements`

In[148]:=

Elements

Out[148]=

{ Hydrogen }

In[149]:=

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

Out[149]=

{ Hydrogen , Helium , Lithium , Beryllium , Boron , Carbon , Nitrogen , Oxygen , Fluorine , Neon , Sodium , Magnesium , Aluminium , Silicon , Phosphorus , Sulfur , Chlorine , Argon , Potassium , Calcium , Scandium , Titanium , Vanadium , Chromium , Manganese , Iron , Cobalt , Nickel , Copper , Zinc , Gallium , Germanium , Arsenic , Selenium , Bromine , Krypton , Rubidium , Strontium , Yttrium , Zirconium , Niobium , Molybdenum , Technetium , Ruthenium , Rhodium , Palladium , Silver , Cadmium , Indium , Tin , Antimony , Tellurium , Iodine , Xenon , Caesium , Barium , Lanthanum , Cerium , Praseodymium , Neodymium , Promethium , Samarium , Europium , Gadolinium , Terbium , Dysprosium , Holmium , Erbium , Thulium , Ytterbium , Lutetium , Hafnium , Tantalum , Tungsten , Rhenium , Osmium , Iridium , Platinum , Gold , Mercury , Thallium , Lead , Bismuth , Polonium , Astatine , Radon , Francium , Radium , Actinium , Thorium }

In[150]:=

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

MeltingPoint :: form : Melting point is for the diamond form of Carbon . "Melting point is for the \\!\\(\\\"diamond\\\"\\) form of \\!\\(Carbon\\)."

MeltingPoint :: form : Melting point is for the P4 form of Phosphorus . "Melting point is for the \\!\\(\\\"P4\\\"\\) form of \\!\\(Phosphorus\\)."

MeltingPoint :: form : Melting point is for the alpha form of Sulfur . "Melting point is for the \\!\\(\\\"alpha\\\"\\) form of \\!\\(Sulfur\\)."

General :: stop : Further output of MeltingPoint :: form will be suppressed during this calculation. More… "Further output of \\!\\(MeltingPoint :: \\\"form\\\"\\) will be suppressed during this calculation. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"General::stop\\\"]\\)"

Out[150]=

{ 14.01 , 0.95 , 453.69 , 1551. , 2573. , 3820. , 63.29 , 54.8 , 53.53 , 24.48 , 370.96 , 922. , 933.5 , 1683. , 317.3 , 386. , 172.2 , 83.8 , 336.8 , 1112. , 1814. , 1933. , 2160. , 2130. , 1517. , 1808. , 1768. , 1726. , 1356.6 , 692.73 , 302.93 , 1210.6 , 83.78 , 490. , 265.9 , 116.6 , 312.2 , 1042. , 1795. , 2125. , 2741. , 2890. , 2445. , 2583. , 2239. , 1825. , 1235.08 , 594.1 , 429.32 , 505.118 , 903.89 , 722.7 , 386.7 , 161.3 , 301.55 , 1002. , 1194. , 1072. , 1204. , 1294. , 1441. , 1350. , 1095. , 1586. , 1629. , 1685. , 1747. , 1802. , 1818. , 1097. , 1936. , 2503. , 3269. , 3680. , 3453. , 3327. , 2683. , 2045. , 1337.58 , 234.28 , 576.6 , 600.65 , 544.5 , 527. , 575. , 202. , 300. , 973. , 1320. , 2023. }

The next plot illustrates the variation of melting temperature as a function of atomic number…

In[151]:=

ListPlot [ mps ]

[Graphics:HTMLFiles/Lecture-05_19.gif]

Out[151]=

Graphics

In[152]:=

ListPlot [ mps , PlotJoined True ]

[Graphics:HTMLFiles/Lecture-05_20.gif]

Out[152]=

Graphics

In[153]:=

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

Density :: temp : Density is for Hydrogen at 11 Kelvin. "Density is for \\!\\(Hydrogen\\) at \\!\\(11\\) Kelvin."

Density :: tempform : Density is for the liquid form of Helium at 4 Kelvin. "Density is for the \\!\\(\\\"liquid\\\"\\) form of \\!\\(Helium\\) at \\!\\(4\\) Kelvin."

Density :: form : Density is for the diamond form of Carbon . "Density is for the \\!\\(\\\"diamond\\\"\\) form of \\!\\(Carbon\\)."

Density :: temp : Density is for Nitrogen at 21 Kelvin. "Density is for \\!\\(Nitrogen\\) at \\!\\(21\\) Kelvin."

Density :: temp : Density is for Oxygen at 55 Kelvin. "Density is for \\!\\(Oxygen\\) at \\!\\(55\\) Kelvin."

General :: stop : Further output of Density :: temp will be suppressed during this calculation. More… "Further output of \\!\\(Density :: \\\"temp\\\"\\) will be suppressed during this calculation. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"General::stop\\\"]\\)"

Density :: tempform : Density is for the liquid form of Fluorine at 85 Kelvin. "Density is for the \\!\\(\\\"liquid\\\"\\) form of \\!\\(Fluorine\\) at \\!\\(85\\) Kelvin."

Density :: form : Density is for the P4 form of Phosphorus . "Density is for the \\!\\(\\\"P4\\\"\\) form of \\!\\(Phosphorus\\)."

Density :: form : Density is for the alpha form of Sulfur . "Density is for the \\!\\(\\\"alpha\\\"\\) form of \\!\\(Sulfur\\)."

General :: stop : Further output of Density :: form will be suppressed during this calculation. More… "Further output of \\!\\(Density :: \\\"form\\\"\\) will be suppressed during this calculation. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"General::stop\\\"]\\)"

Density :: unknown : The density of Astatine is not known. "The density of \\!\\(Astatine\\) is not known."

Density :: tempform : Density is for the liquid form of Radon at 211 Kelvin. "Density is for the \\!\\(\\\"liquid\\\"\\) form of \\!\\(Radon\\) at \\!\\(211\\) Kelvin."

General :: stop : Further output of Density :: tempform will be suppressed during this calculation. More… "Further output of \\!\\(Density :: \\\"tempform\\\"\\) will be suppressed during this calculation. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"General::stop\\\"]\\)"

Density :: unknown : The density of Francium is not known. "The density of \\!\\(Francium\\) is not known."

Out[153]=

{ 76. , 124.8 , 534. , 1847.7 , 2340. , 3513. , 1026. , 2000. , 1516. , 1444. , 971. , 1738. , 2698. , 2329. , 1820. , 2070. , 2030. , 1656. , 862. , 1550. , 2989. , 4540. , 6110. , 7190. , 7440. , 7874. , 8900. , 8902. , 8960. , 7133. , 5907. , 5323. , 5780. , 4790. , 4050. , 2823. , 1532. , 2540. , 4469. , 6506. , 8570. , 10220. , 11500. , 12370. , 12410. , 12020. , 10500. , 8650. , 7310. , 7310. , 6691. , 6240. , 4930. , 3540. , 1873. , 3594. , 6145. , 8240. , 6773. , 7007. , 7220. , 7520. , 5243. , 7900.4 , 8229. , 8550. , 8795. , 9066. , 9321. , 6965. , 9840. , 13310. , 16654. , 19300. , 21020. , 22590. , 22420. , 21450. , 19320. , 13546. , 11850. , 11350. , 9747. , 9320. , Unknown , 4400. , Unknown , 5000. , 10060. , 11720. }

The next line matches up values of density with melting temperature…

In[154]:=

dmdata = Transpose [ { Dens , mps } ]

Out[154]=

{ { 76. , 14.01 } , { 124.8 , 0.95 } , { 534. , 453.69 } , { 1847.7 , 1551. } , { 2340. , 2573. } , { 3513. , 3820. } , { 1026. , 63.29 } , { 2000. , 54.8 } , { 1516. , 53.53 } , { 1444. , 24.48 } , { 971. , 370.96 } , { 1738. , 922. } , { 2698. , 933.5 } , { 2329. , 1683. } , { 1820. , 317.3 } , { 2070. , 386. } , { 2030. , 172.2 } , { 1656. , 83.8 } , { 862. , 336.8 } , { 1550. , 1112. } , { 2989. , 1814. } , { 4540. , 1933. } , { 6110. , 2160. } , { 7190. , 2130. } , { 7440. , 1517. } , { 7874. , 1808. } , { 8900. , 1768. } , { 8902. , 1726. } , { 8960. , 1356.6 } , { 7133. , 692.73 } , { 5907. , 302.93 } , { 5323. , 1210.6 } , { 5780. , 83.78 } , { 4790. , 490. } , { 4050. , 265.9 } , { 2823. , 116.6 } , { 1532. , 312.2 } , { 2540. , 1042. } , { 4469. , 1795. } , { 6506. , 2125. } , { 8570. , 2741. } , { 10220. , 2890. } , { 11500. , 2445. } , { 12370. , 2583. } , { 12410. , 2239. } , { 12020. , 1825. } , { 10500. , 1235.08 } , { 8650. , 594.1 } , { 7310. , 429.32 } , { 7310. , 505.118 } , { 6691. , 903.89 } , { 6240. , 722.7 } , { 4930. , 386.7 } , { 3540. , 161.3 } , { 1873. , 301.55 } , { 3594. , 1002. } , { 6145. , 1194. } , { 8240. , 1072. } , { 6773. , 1204. } , { 7007. , 1294. } , { 7220. , 1441. } , { 7520. , 1350. } , { 5243. , 1095. } , { 7900.4 , 1586. } , { 8229. , 1629. } , { 8550. , 1685. } , { 8795. , 1747. } , { 9066. , 1802. } , { 9321. , 1818. } , { 6965. , 1097. } , { 9840. , 1936. } , { 13310. , 2503. } , { 16654. , 3269. } , { 19300. , 3680. } , { 21020. , 3453. } , { 22590. , 3327. } , { 22420. , 2683. } , { 21450. , 2045. } , { 19320. , 1337.58 } , { 13546. , 234.28 } , { 11850. , 576.6 } , { 11350. , 600.65 } , { 9747. , 544.5 } , { 9320. , 527. } , { Unknown , 575. } , { 4400. , 202. } , { Unknown , 300. } , { 5000. , 973. } , { 10060. , 1320. } , { 11720. , 2023. } }

In[155]:=

ListPlot [ dmdata ]

Graphics :: gptn : Coordinate Unknown in { Unknown , 575. } is not a floating-point number. More… "Coordinate \\!\\(Unknown\\) in \\!\\({Unknown, 575.`}\\) is not a floating-point number. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"Graphics::gptn\\\"]\\)"

Graphics :: gptn : Coordinate Unknown in { Unknown , 300. } is not a floating-point number. More… "Coordinate \\!\\(Unknown\\) in \\!\\({Unknown, 300.`}\\) is not a floating-point number. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"Graphics::gptn\\\"]\\)"

[Graphics:HTMLFiles/Lecture-05_21.gif]

Out[155]=

Graphics

In[156]:=

ListPlot [ dmdata , PlotJoined True ]

Graphics :: gptn : Coordinate Unknown in { Unknown , 575. } is not a floating-point number. More… "Coordinate \\!\\(Unknown\\) in \\!\\({Unknown, 575.`}\\) is not a floating-point number. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"Graphics::gptn\\\"]\\)"

Graphics :: gptn : Coordinate Unknown in { Unknown , 300. } is not a floating-point number. More… "Coordinate \\!\\(Unknown\\) in \\!\\({Unknown, 300.`}\\) is not a floating-point number. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"Graphics::gptn\\\"]\\)"

[Graphics:HTMLFiles/Lecture-05_22.gif]

Out[156]=

Graphics

Three-Dimensional Graphics

Plot3D, ContourPlot, DensityPlot, etc

In[157]:=

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

In[158]:=

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

SheetOLatticeCharge represents the electric field produced by an 11 by 11 array of point charges arranged on the x-y plane at z = 0. The following command evaluates and plots the field variation in the plane z = 0.25:

In[159]:=

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

[Graphics:HTMLFiles/Lecture-05_23.gif]

Out[159]=

SurfaceGraphics

Note below how theplot is set to contain the output of the Plot3D command.

In[160]:=

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

[Graphics:HTMLFiles/Lecture-05_24.gif]

Out[160]=

SurfaceGraphics

Now we can adjust the viewpoint of theplot, without recalculating the entire plot, using the Show command:

In[161]:=

? Show

Show[graphics, options] displays two- and three-dimensional graphics, using the options specified. Show[g1, g2, ... ] shows several plots combined. More…

In[162]:=

? Show

Show[graphics, options] displays two- and three-dimensional graphics, using the options specified. Show[g1, g2, ... ] shows several plots combined. More…

In[163]:=

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

[Graphics:HTMLFiles/Lecture-05_25.gif]

Out[163]=

SurfaceGraphics

In[164]:=

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

[Graphics:HTMLFiles/Lecture-05_26.gif]

Out[164]=

ContourGraphics

In[165]:=

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

[Graphics:HTMLFiles/Lecture-05_27.gif]

Out[165]=

ContourGraphics

In[166]:=

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

[Graphics:HTMLFiles/Lecture-05_28.gif]

Out[166]=

DensityGraphics

In[167]:=

Show [ thedenplot , Mesh False ]

[Graphics:HTMLFiles/Lecture-05_29.gif]

Out[167]=

DensityGraphics

Graphics Primitives

It can be useful to be able to build up arbitrary graphics objects piece-by-piece using simple "graphics primitives" like Circle:

In[168]:=

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

[Graphics:HTMLFiles/Lecture-05_30.gif]

Out[168]=

Graphics

In[169]:=

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

[Graphics:HTMLFiles/Lecture-05_31.gif]

Out[169]=

Graphics

In[170]:=

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

[Graphics:HTMLFiles/Lecture-05_32.gif]

Out[170]=

Graphics

Now we take a simple plot…

In[171]:=

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

[Graphics:HTMLFiles/Lecture-05_33.gif]

Out[171]=

Graphics

and overlay some text in places of our own choosing…

In[172]:=

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

[Graphics:HTMLFiles/Lecture-05_34.gif]

Out[172]=

Graphics

Many processes in the natural world can be modelled by random walks. An example is the trajectory of a particular  molecule in a gas at low pressure.  The next few lines of code produce random walks and display them graphically:

In[173]:=

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

Out[173]=

{ 0 , { 0 , 0 } }

In[174]:=

randomwalk [ 0 ] [ [ 2 ] ]

Out[174]=

{ 0 , 0 }

In[175]:=

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

In[176]:=

randomwalk [ 4 ]

Out[176]=

{ 4 , { 0.5993225470251821 , 0.19324709113253935 } }

In[177]:=

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

[Graphics:HTMLFiles/Lecture-05_35.gif]

Out[177]=

Graphics

In[178]:=

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 } ]

[Graphics:HTMLFiles/Lecture-05_36.gif]

Out[178]=

Graphics

In[179]:=

<< Graphics`Animation`

In[180]:=

ShowAnimation [ Table [ Graphics [ { Text [ ToString [ randomwalk [ i ] [ [ 1 ] ] ] , randomwalk [ i ] [ [ 2 ] ] ] , Line [ { randomwalk [ i ] [ [ 2 ] ] , randomwalk [ i + 1 ] [ [ 2 ] ] } ] } ] , { i , 0 , 49 } ] , PlotRange { { - 3 , 3 } , { - 3 , 3 } } , AspectRatio 1 , AxesOrigin { 0 , 0 } ]

[Graphics:HTMLFiles/Lecture-05_87.gif]

In[181]:=

ShowAnimation [ Table [ Graphics [ Table [ { Text [ ToString [ randomwalk [ j ] [ [ 1 ] ] ] , randomwalk [ j ] [ [ 2 ] ] ] , Line [ { randomwalk [ j ] [ [ 2 ] ] , randomwalk [ j + 1 ] [ [ 2 ] ] } ] } , { j , 0 , i } ] ] , { i , 0 , 49 } ] , PlotRange { { - 3 , 3 } , { - 3 , 3 } } , AspectRatio 1 , AxesOrigin { 0 , 0 } ]

[Graphics:HTMLFiles/Lecture-05_138.gif]

In[182]:=

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 } } ] ] ]

Out[182]=

Graphics

These last two plots have to do with the orientation dependence of the surface energy of a 2-D crystal (GammaPlot)and the equilibrium shape that a single crystal having this surface energy will adopt to minimize its total surface energy.

In[183]:=

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

In[184]:=

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

[Graphics:HTMLFiles/Lecture-05_139.gif]

Out[184]=

Graphics

In[185]:=

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

[Graphics:HTMLFiles/Lecture-05_140.gif]

Out[185]=

Graphics

The inner envelope of the tangent lines to the GammaPlot in the figure above illustrates the energy-minimizing shape of the crystal. For this particular GammaPlot, the shape is approximately a square but the corners are rounded.

XML`MathML`BoxesToMathML :: notboxes : { BoltzmannConstant , ElectronCharge , SpeedOfLight } is not a valid box structure. The first argument in XML`MathML`BoxesToMathML [ { BoltzmannConstant , ElectronCharge , SpeedOfLight } , 2 , ] must be a valid box structure. More… "\\!\\({\\\"BoltzmannConstant\\\", \\\"ElectronCharge\\\", \\\"SpeedOfLight\\\"}\\) is not a valid box structure. The first argument in \\!\\(XML`MathML`BoxesToMathML[\\(\\(\\(\\({\\\"BoltzmannConstant\\\", \\\"ElectronCharge\\\", \\\"SpeedOfLight\\\"}\\)\\), \\(\\(\[LeftSkeleton] 2 \[RightSkeleton]\\)\\), \\(\\(\\(\\(\\\"\\\"\[Ellipsis]\\\"\\\"\\)\\) \[Rule] \\(\\(\\\"\\\"\[Ellipsis]\\\"\\\"\\)\\)\\)\\)\\)\\)]\\) must be a valid box structure. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"XML`MathML`BoxesToMathML::notboxes\\\"]\\)"

Export :: noopen : Cannot open /Volumes/Users_Partition_Primary/ccarter/c 6/Web/MathMATHML/Lecture-05/Lecture-05.xml . More… "Cannot open \\!\\(\\\"/Volumes/Users_Partition_Primary/ccarter/c\\\"\[Ellipsis]\\\"6/Web/MathMATHML/Lecture-05/Lecture-05.xml\\\"\\). \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"General::noopen\\\"]\\)"

Export :: noopen : Cannot open /Volumes/Users_Partition_Primary/ccarter/c 6/Web/MathMATHML/Lecture-05/Lecture-05.xml . More… "Cannot open \\!\\(\\\"/Volumes/Users_Partition_Primary/ccarter/c\\\"\[Ellipsis]\\\"6/Web/MathMATHML/Lecture-05/Lecture-05.xml\\\"\\). \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"General::noopen\\\"]\\)"

Export :: noopen : Cannot open /Volumes/Users_Partition_Primary/ccarter/c 6/Web/MathMATHML/Lecture-05/Lecture-05.xml . More… "Cannot open \\!\\(\\\"/Volumes/Users_Partition_Primary/ccarter/c\\\"\[Ellipsis]\\\"6/Web/MathMATHML/Lecture-05/Lecture-05.xml\\\"\\). \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"General::noopen\\\"]\\)"

Export :: noopen : Cannot open /Volumes/Users_Partition_Primary/ccarter/c 6/Web/MathMATHML/Lecture-05/Lecture-05.xml . More… "Cannot open \\!\\(\\\"/Volumes/Users_Partition_Primary/ccarter/c\\\"\[Ellipsis]\\\"6/Web/MathMATHML/Lecture-05/Lecture-05.xml\\\"\\). \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, ButtonData:>\\\"General::noopen\\\"]\\)"


Created by Mathematica  (September 15, 2005) Valid XHTML 1.1!