Sei sulla pagina 1di 41

Data Visualization

with
Mathematica

Philadelphia Math + Science Coalition


www.philaedfund.org/programs/advancing-education/philadelphia-math-science-
coalition
United Way Building
1709 Benjamin Franklin Parkway, Suite 700
Philadelphia, PA 19103

March 8, 2010

Edward Bujak
Edward_Bujak@hotmail.com

Goals :
To explore and dynamically interact easily with large real-time data sets visually, graphically, algebraically.
Manipulate data and its creative presentation to maximize information transfer utilizing numeric, textual, and/or image representa-
tions.

2 Methods :
Import[ ] function allows us to process data from personal files.
<Name>Data[ ] functions allow us to manipulate large amounts of real-world data into Mathematica from Wolfram's Integrated
Data Sources (Curated Data Sources).

Notes :
With data we have values, not functions. So the data is discrete, not continuous.
In Mathematica the data can be anything, not just numbers.
2 Data Visualization with Mathematica.03.nb

Mathematica

Mathematica files are notebooks (.NB).


Each notebook is organized by grouped cells indicated by nested brackets on the right. Cells can be collapsed/expanded.
Almost any type of object can be copied/pasted anywhere or saved as a file.
Ther are numerous types of help: palettes, application (live) documentation, online (live) documentation, support.
The documentation is live and written in Mathematica.

Deployment options:
1. Notebook Player - I can share this interactivity with anyone who does not have Mathematica. User needs to download the
free Mathematica Player - www.wolfram.com/products/player. The author needs to publish the notebook (.NB) into a notebook
player (.NBP) file with Wolfram Mathematica Player: Online Conversion - www.wolfram.com/solutions/interactivedeployment/publish
2. Slideshow generator via "Slide Show palette" - dynamic, live - need the free Notebook Player if you do not have Mathemat-
ica.
3. “Demonstration” - dynamic interactivity with Manipulate[] to create virtual manipulatives that can be hosted at Wolfram's
Demonstrations site - http://demonstrations.wolfram.com
4. Can save almost anything (including cell, selections) as static RTF, PDF, HTML, TeX, TXT, PS, XML, package, GIF, JPG,
PNG, TIFF, BMP, WMF, LATE X, MathML

5. Quiz generator.

Mathematica Syntax

Mathematica is symbolic. As in all CAS (Computer Algebrais Systems], the presentation of the mathematical results may some-
times look non "traditional." Sometimes may want TraditionalForm[] or set a system preference to always display tradtional form..
[ ] ® function
{ } ® lists and sets
( ) ® grouping
[[ ]] ® indexing

= ® assignment
== ® logical equal
:= ® function definition

x®3 is a "rule," read as x gets 3

Mathematica functions are mixed-case and start upper-case.


Do-Loop Construct
Data Visualization with Mathematica.03.nb 3

? Table

Tableexpr, imax  generates a list of imax copies of expr.


Tableexpr, i, imax  generates a list of the values of expr when i runs from 1 to imax .
Tableexpr, i, imin , imax  starts with i = imin .
Tableexpr, i, imin , imax , di uses steps di.
Tableexpr, i, i1 , i2 , … uses the successive values i1 , i2 , ….
Tableexpr, i, imin , imax ,  j, jmin , jmax , … gives a nested list. The list associated with i is outermost. ‡

Table 2 x  1, x, 1, 6

3, 5, 7, 9, 11, 13

Table x, 2 x, 2 x  5, 2 x4 , x, 1, 6

1 2 7 2
2 4 9 32
3 6 11 162
4 8 13 512
5 10 15 1250
6 12 17 2592

Many more such as conditionals (if), user-defined functions.


Can program procedurally, functionally, and/or rule-based.
Built in mathematical algorithm selection is optimally chosen for problem, but can be over-ridden.
Parallel computing - within one CPU across cores and/or across CPUs - this is great for multi-core CPUs, during time-consuming
operations to allow you to do other work on the file.

Mathematica Visualization Capabilities

Looking at some visualization capbabilities. Remember that data is discrete so the Mathematica functions that utilize a mathemati-
cal function can only be used after the data is modeled with a function.

sizeImageNotebook  200;

PlotSinx, x, 0, 2 , ImageSize  sizeImageNotebook

1.0

0.5

1 2 3 4 5 6

-0.5

-1.0
4 Data Visualization with Mathematica.03.nb

Plot3DSinx  y2 , x, 3, 3,


y, 2, 2, ImageSize  sizeImageNotebook

1.0
0.5
2
0.0
-0.5 1
-1.0
0
-2
0 -1

2 -2

ContourPlotSinx  y2 , x, 3, 3,


y, 2, 2, ImageSize  sizeImageNotebook

-1

-2
-3 -2 -1 0 1 2 3

DiscretePlotPrimek, k, 1, 50, ImageSize  sizeImageNotebook

200

150

100

50

10 20 30 40 50

Everything can be changed, decorated, annotated via options (PlotStyle is a graphic option) and directives. This can be easily
accessed from the "Chart Element Schemes" and the "Color Schemes"palettes.
Hover cursor over any point to be shown the data value in the tooltip.
Data Visualization with Mathematica.03.nb 5

data1  ListPlotTooltip3, 4, 5,


PlotStyle  PointSize0.025, Red,
ImageSize  sizeImageNotebook

5.0

4.5

4.0

3.5

0.5 1.0 1.5 2.0 2.5 3.0

data2  ListLinePlot3, 4, 5,


PlotStyle  Dashed, Magenta, ImageSize  sizeImageNotebook

5.0

4.5

4.0

3.5

0.5 1.0 1.5 2.0 2.5 3.0

Can combine many graphs:

Showdata1, data2

5.0

4.5

4.0

3.5

0.5 1.0 1.5 2.0 2.5 3.0


6 Data Visualization with Mathematica.03.nb

ListLinePlotAccumulateRandomReal1, 1, 250,


ColorFunction  "Rainbow", Filling  Axis,
ImageSize  sizeImageNotebook

15

10

50 100 150 200 250

starData  TableCosk 2 Pi  7, Sink 2 Pi  7, k, 0, 21, 3

-cos  sin 
1 0
Π Π

 -cos 
7 7
3Π 3Π
sin

 
14 14
Π Π
-sin cos

 -cos 
14 14
Π Π
-sin

 
14 14
3Π 3Π
sin cos

-cos  -sin 
14 14
Π Π
7 7
1 0

NstarData

1. 0.
-0.900969 0.433884
0.62349 -0.781831
-0.222521 0.974928
-0.222521 -0.974928
0.62349 0.781831
-0.900969 -0.433884
1. 0.

ListLinePlotTooltipstarData, Frame  True,


Axes  False, ImageSize  sizeImageNotebook

1.0

0.5

0.0

-0.5

-1.0
-0.5 0.0 0.5 1.0
Data Visualization with Mathematica.03.nb 7

ListPlot3D0, 0, 1, 1, 0, 0, 0, 1, 0,


Mesh  All, ImageSize  sizeImageNotebook

1.0
1.0
0.5

0.0
0.0 0.5

0.5

0.0
1.0

dataSteps  TableSinj^2  i, i, 0, Pi, Pi  5, j, 0, Pi, Pi  5

    sinΠ2 
Π2 4 Π2 9 Π2 16 Π2
0 sin sin sin sin
25 25 25 25

    sin + Π2 
5 5 Π Π2 Π 4 Π2 Π 9 Π2 Π 16 Π2 Π
- sin + sin + sin + sin +
8 8 5 25 5 25 5 25 5 25 5

 cos  cos  cos  cos - Π2 


5 5 Π Π2 Π 4 Π2 Π 9 Π2 Π 16 Π2 Π
+ cos - - - -
8 8 10 25 10 25 10 25 10 25 10

 cos  cos  cos  cos + Π2 


5 5 Π Π2 Π 4 Π2 Π 9 Π2 Π 16 Π2 Π
+ cos + + + +
8 8 10 25 10 25 10 25 10 25 10

    sin - Π2 
5 5 Π Π2 Π 4 Π2 Π 9 Π2 Π 16 Π2 Π
- sin - sin - sin - sin -
8 8 5 25 5 25 5 25 5 25 5

    -sinΠ2 
Π2 4 Π2 9 Π2 16 Π2
0 -sin -sin -sin -sin
25 25 25 25

ListPlot3DdataSteps, Mesh  None, InterpolationOrder  0,


ColorFunction  "SouthwestColors", ImageSize  sizeImageNotebook

1.0
0.5
6
0.0
-0.5
-1.0 4
2

4 2

6
8 Data Visualization with Mathematica.03.nb

u, 0, 2 Pi, ImageSize  sizeImageNotebook


ParametricPlotSin2 u, Sin3 u,

1.0

0.5

-1.0 -0.5 0.5 1.0

-0.5

-1.0

ParametricPlotr^2  Sqrtt Cost, Sint,


t, 0, 3 Pi  2, r, 1, 2, ImageSize  sizeImageNotebook

-2

-4
-6 -4 -2 0 2
Data Visualization with Mathematica.03.nb 9

ParametricPlot3D

t  ,
Cost Sint t
, t  ,

t, 6 , 6 ,
10 10 10

ImageSize  sizeImageNotebook,
PlotStyle  Thick, Red

1
0
-1

-1

-1
0
1

ParametricPlot3D1.16^v Cosv 1  Cosu,


1.16^v Sinv 1  Cosu, 2 1.16^v 1  Sinu,
u, 0, 2 Pi, v, 15, 6, Mesh  None, PlotStyle  Opacity0.6,
PlotRange  All, PlotPoints  25, ImageSize  sizeImageNotebook

PolarPlotSin5 t, t, 0, , ImageSize  sizeImageNotebook

1.0

0.5

-0.5 0.5

-0.5
10 Data Visualization with Mathematica.03.nb

ReliefPlotTablei  Sini^2  j^2, i, 4, 4, .03, j, 4, 4, .03,


ColorFunction  "SunsetColors", ImageSize  sizeImageNotebook

GraphPlotTablei  Modi^2, 102, i, 0, 102

A 100-node random graph with 1% of possible edges filled in:


Data Visualization with Mathematica.03.nb 11

GraphPlotRandomChoice0.01, 0.99  1, 0, 100, 100

Layered graphs.

LayeredGraphPlot1  2, 1  3, 2  3, 1  4, 2  4, 1  5,
VertexLabeling  True, ImageSize  sizeImageNotebook

5 2

3 4
12 Data Visualization with Mathematica.03.nb

"John"  "plants", "lion"  "John", "tiger"  "John",


LayeredGraphPlot

"tiger"  "deer", "lion"  "deer", "deer"  "plants",


"mosquito"  "lion", "frog"  "mosquito", "mosquito"  "tiger",
"John"  "cow", "cow"  "plants", "mosquito"  "deer",
"mosquito"  "John", "snake"  "frog", "vulture"  "snake",
Left, VertexLabeling  True, ImageSize  700

tiger deer

vulture snake frog mosquito lion John

cow

And many more:


ListPlot, DateListPlot, ListLogPlot,
RegionPlot, RegionPlot3D, DensityPlot, ListDensityPlot , ContourPlot, ArrayPlot, RegionPlot, StreamPlot, VectorPlot, StreamDensi-
tyPlot, VectordensityPlot,
StreamPlot ä VectorPlot ä StreamDensityPlot ä VectorDensityPlot
RevolutionPlot3D, ParametricPlot3D, TreePlot

Import [ ] and Fitting Model to Data

Import and Export can handle not only tabular data, but also data corresponding to graphics, sounds, expressions and even

whole documents. Import and Export can often deduce the appropriate format for data simply by looking at the extension of the
file name for the file in which the data is being stored. "Exporting Graphics and Sounds" and "Importing and Exporting Files" discuss
in more detail how Import and Export work. Note that you can also use Import and Export to manipulate raw files of binary
data.
Data Visualization with Mathematica.03.nb 13

$ImportFormats

3DS, ACO, AIFF, ApacheLog, AU, AVI, Base64, Binary, Bit, BMP, Byte, BYU, BZIP2, CDED, CDF, Character16, Character8,
Complex128, Complex256, Complex64, CSV, CUR, DBF, DICOM, DIF, Directory, DXF, EDF, ExpressionML, FASTA, FITS,
FLAC, GenBank, GeoTIFF, GIF, Graph6, GTOPO30, GZIP, HarwellBoeing, HDF, HDF5, HTML, ICO, Integer128, Integer16,
Integer24, Integer32, Integer64, Integer8, JPEG, JPEG2000, JVX, LaTeX, List, LWO, MAT, MathML, MBOX, MDB, MGF,
MMCIF, MOL, MOL2, MPS, MTP, MTX, MX, NB, NetCDF, NOFF, OBJ, ODS, OFF, Package, PBM, PCX, PDB, PDF,
PGM, PLY, PNG, PNM, PPM, PXR, QuickTime, RawBitmap, Real128, Real32, Real64, RIB, RSS, RTF, SCT, SDF, SDTS,
SDTSDEM, SHP, SMILES, SND, SP3, Sparse6, STL, String, SXC, Table, TAR, TerminatedString, Text, TGA, TIFF, TIGER,
TSV, UnsignedInteger128, UnsignedInteger16, UnsignedInteger24, UnsignedInteger32, UnsignedInteger64, UnsignedInteger8,
USGSDEM, UUE, VCF, WAV, Wave64, WDX, XBM, XHTML, XHTMLMathML, XLS, XML, XPORT, XYZ, ZIP

$ExportFormats

3DS, ACO, AIFF, AU, AVI, Base64, Binary, Bit, BMP, Byte, BYU, BZIP2, CDF, Character16, Character8, Complex128,
Complex256, Complex64, CSV, DICOM, DIF, DXF, EMF, EPS, ExpressionML, FASTA, FITS, FLAC, FLV, GIF, Graph6,
GZIP, HarwellBoeing, HDF, HDF5, HTML, Integer128, Integer16, Integer24, Integer32, Integer64, Integer8, JPEG,
JPEG2000, JVX, List, LWO, MAT, MathML, Maya, MGF, MIDI, MOL, MOL2, MTX, MX, NB, NetCDF, NOFF, OBJ,
OFF, Package, PBM, PCX, PDB, PDF, PGM, PLY, PNG, PNM, POV, PPM, PXR, RawBitmap, Real128, Real32, Real64,
RIB, RTF, SCT, SDF, SND, Sparse6, STL, String, SVG, SWF, Table, TAR, TerminatedString, TeX, Text, TGA, TIFF, TSV,
UnsignedInteger128, UnsignedInteger16, UnsignedInteger24, UnsignedInteger32, UnsignedInteger64, UnsignedInteger8,
UUE, VRML, WAV, Wave64, WDX, WMF, X3D, XBM, XHTML, XHTMLMathML, XLS, XML, XYZ, ZIP, ZPR

? Import

Import" file" imports data from a file, returning a complete Mathematica version of it.
Import" file", elements imports the specified elements from a file.
Import"http:url", … and Import"ftp:url", … imports from any accessible URL. ‡

? Fit

Fitdata, funs, vars finds a least-squares fit to


a list of data as a linear combination of the functions funs of variables vars. ‡

? FindFit

best fit to data as a function of vars. The data can have the form x1 , y1 , …, f1 , x2 , y2 , …, f2 , …,
FindFitdata, expr, pars, vars finds numerical values of the parameters pars that make expr give a

data can also be of the form  f1 , f2 , …, with a single coordinate assumed to take values 1, 2, ….
where the number of coordinates x, y, … is equal to the number of variables in the list vars. The

FindFitdata, expr, cons, pars, vars finds a best fit subject to the parameter constraints cons. ‡

$DataDirectory  ToFileNameNotebookDirectory, "Data";


14 Data Visualization with Mathematica.03.nb

$DataDirectory

J:\presentations\Data Visualization with Mathematica\Data\

AppendTo$Path, $DataDirectory;

$Path

C:\Program Files\Wolfram Research\Mathematica\7.0\SystemFiles\Links,


C:\Documents and Settings\Ed\Application Data\Mathematica\Kernel,
C:\Documents and Settings\Ed\Application Data\Mathematica\Autoload,
C:\Documents and Settings\Ed\Application Data\Mathematica\Applications,
C:\Documents and Settings\All Users\Application Data\Mathematica\Kernel,
C:\Documents and Settings\All Users\Application Data\Mathematica\Autoload,
C:\Documents and Settings\All Users\Application Data\Mathematica\Applications, .,
C:\Documents and Settings\Ed, C:\Program Files\Wolfram Research\Mathematica\7.0\AddOns\Packages,
C:\Program Files\Wolfram Research\Mathematica\7.0\AddOns\LegacyPackages,
C:\Program Files\Wolfram Research\Mathematica\7.0\SystemFiles\Autoload,
C:\Program Files\Wolfram Research\Mathematica\7.0\AddOns\Autoload,
C:\Program Files\Wolfram Research\Mathematica\7.0\AddOns\Applications,
C:\Program Files\Wolfram Research\Mathematica\7.0\AddOns\ExtraPackages,
C:\Program Files\Wolfram Research\Mathematica\7.0\SystemFiles\Kernel\Packages,
C:\Program Files\Wolfram Research\Mathematica\7.0\Documentation\English\System,
J:\presentations\Data Visualization with Mathematica\Data\

Fitting a model to a series of (x,y) data values:

dataLinear  Import"data.xls", "Data", 1;


dataPlotLinear 
ListPlotTooltipdataLinear, PlotStyle  PointSize0.02, Green

50

40

30

2 4 6 8 10

Fit the data to the model a x + b.


Data Visualization with Mathematica.03.nb 15

Clear a, b;


fitLinear  FindFitdataLinear, a x  b, a, b, x

a ® 4.61415, b ® 8.924

Display the fit function together with the data.

Plota x  b . fitLinear, x, 0, 10, PlotStyle  Red


ShowdataPlotLinear,

50

40

30

2 4 6 8 10

Fitting non-linear data.

dataNoisy  Import"noisydata.xls", "Data", 1;


dataNoisyPlot  ListPlotdataNoisy

1.0

0.5

1 2 3 4 5 6

-0.5

-1.0

Fit the data to the model Α + sinx Β + Γ sin∆ x.

fit  FindFitdataNoisy,   Sin x   Sin x, , , , , x

Α ® 0.00718779, Β ® 1.00277, Γ ® 1.41681, ∆ ® 0.999737

Display the fit function together with the data.


16 Data Visualization with Mathematica.03.nb

Display the fit function together with the data.

Plot  Sin x   Sin x . fit, x, 0, 6.3, PlotStyle  Red


ShowdataNoisyPlot,

1.0

0.5

1 2 3 4 5 6

-0.5

-1.0

The next example fits a nonlinear model to some astronomical data.


This imports a data file consisting of timing residuals for the pulsar PSR1257+12 spanning a three-year period (kindly supplied by
Alex Wolszczan).

dataPulsar  Import"pulsar1257.dat", "Table";


Display the pulsar data:

dataPulsar

0.687021 -0.0188495
0.719811 -0.335115
0.730804 -0.52507
0.796315 0.257191
0.845486 2.15298
0.861925 2.10726
0.952068 -2.59551
0.95484 -2.62171
0.973977 -2.32315
0.976714 -2.22064
1.20073 -0.568935
1.21987 -0.150349
Data Visualization with Mathematica.03.nb 17

1.21987 -0.150349
1.30188 -0.488403
1.30455 -0.494481
1.31002 -0.469674
1.39201 1.94947
1.39477 1.97185
1.44655 0.0107999
1.44664 0.0066815
1.55317 -0.0770058
1.55587 0.128978
1.59684 2.46479
1.59966 2.52511
1.63513 1.86379
1.67874 -0.689795
1.68151 -0.815304
1.6897 -1.12602
1.70062 -1.37461
1.71974 -1.37764
1.76346 -0.223993
1.76619 -0.155781
1.80171 0.231833
1.80456 0.218089
1.80735 0.19759
1.82358 0.02412
1.82634 -0.0089064
1.8509 -0.22583
1.85364 -0.222086
1.86456 -0.150962
1.88094 0.176626
1.88366 0.253788
1.90829 1.07285
1.91101 1.16397
1.91379 1.24854
1.91918 1.40647
1.92192 1.46948
1.96838 1.15017
1.99029 -0.019696
2.06935 -1.89477
2.12112 1.7299
2.13467 2.39416
2.15652 2.67063
2.15925 2.63692
2.18661 1.47038
2.19189 1.12811
2.19464 0.939938
2.26282 -1.63623
2.29831 -0.571845
18 Data Visualization with Mathematica.03.nb

2.29831 -0.571845
2.30105 -0.467178
2.3038 -0.370373
2.30653 -0.27104
2.30923 -0.185139
2.31196 -0.100059
2.31473 -0.0191635
2.31741 0.0613637
2.32012 0.135984
2.32288 0.193437
2.32562 0.262972
2.33105 0.3573
2.3336 0.386537
2.38549 0.108196
2.3882 0.0782136
2.41802 0.0979297
2.41909 0.116686
2.4208 0.139112
2.49979 1.2944
2.50256 1.23173
2.55708 -1.44589
2.55979 -1.58387
2.57344 -2.143
2.57619 -2.21118
2.66331 1.77407
2.66602 1.93837
2.72048 2.01038
2.7232 1.85777
2.75059 -0.0428941
2.75592 -0.405188
2.75867 -0.595059
2.78859 -1.85679
2.79134 -1.89844
2.83763 -0.804781
2.84038 -0.68503
2.87312 0.49313
2.87584 0.550665
2.91669 0.564317
2.96028 0.154039
2.96302 0.17036
3.02575 1.16419
3.02851 1.17307
3.08589 -0.619972
3.08867 -0.764877
3.12139 -2.11591
3.1706 -0.76415
3.17332 -0.576337
Data Visualization with Mathematica.03.nb 19

3.23625 2.80614
3.2389 2.80191
3.26894 1.70996
3.2717 1.52628
3.27441 1.34718
3.27716 1.15426
3.27988 0.958417
3.2826 0.752647
3.28539 0.542753
3.28809 0.337932
3.29353 -0.0750401
3.29624 -0.274558
3.299 -0.47054
3.30172 -0.667524
3.30445 -0.851145
3.30719 -1.02325
3.31267 -1.34591
3.3154 -1.48888
3.31809 -1.61345
3.32085 -1.73499
3.3263 -1.91916
3.32906 -1.9923
3.33182 -2.04945
3.33455 -2.09106
3.38369 -0.774774
3.38643 -0.647009
3.43013 0.938914
3.4312 0.951182
3.43291 0.967501
3.47933 0.531234
3.48206 0.479443
3.52028 0.222164
3.54214 0.516191
3.54486 0.560826
3.55033 0.649746
3.55852 0.771456
3.56671 0.857604
3.56947 0.87025
3.57219 0.882395
3.57496 0.889598
3.58044 0.873126
3.58584 0.832191
3.5886 0.800181
3.5914 0.757595
3.59404 0.708435
3.59676 0.654172
3.59952 0.585253
20 Data Visualization with Mathematica.03.nb

3.59952 0.585253
3.60227 0.513836
3.60496 0.43218
3.60775 0.345518
3.6241 -0.303461
3.62692 -0.430591
3.63231 -0.679269
3.63502 -0.809463
3.63778 -0.929009
3.64049 -1.05495
3.64323 -1.18237
3.64596 -1.30095
3.65144 -1.5187
3.65414 -1.6279
3.65689 -1.70974
3.65962 -1.79757
3.66236 -1.87084
3.6651 -1.93
3.71426 -0.703003
3.71701 -0.515862
3.76086 2.36768
3.76342 2.46275

dataPulsarPlot 
1
ListPlotdataPulsar, AspectRatio  , PlotStyle  Red
2
3

1.5 2.0 2.5 3.0 3.5


-1

-2

Here is the nonlinear model we will use for the fit.


Ε + Β cos(t Θ) + ∆ cos(t Φ) + Α sin(t Θ) + Γ sin(t Φ)

This computes the regression using nondefault starting values for the parameters.

params  FindFitdataPulsar,
 Sin t   Cos t   Sin t   Cos t  ,
, 1, , 1, , 1, , 0, , 23.31, , 34.64, , 0, t

Α ® 0.46115, Β ® 1.33261, Γ ® -1.29803, ∆ ® 0.209533, Θ ® 23.3869, Φ ® 34.5111, Ε ® 0.0769581

This plot shows the quality of the nonlinear fit.


Data Visualization with Mathematica.03.nb 21

ShowPlot Sin t   Cos t   Sin t   Cos t   . params,


t, 0.68, 3.76,
dataPulsarPlot

1.5 2.0 2.5 3.0 3.5

-1

-2

xxxxData[] - Curated Data Sources - Integrated Data Sources - What Kind of Data Collections?

xxxxData functions :
An efficient load-on-demand mechanism makes hundreds of gigabytes of carefully curated and continually updated data immedi-
ately available inside Mathematica for use in computations. This data, curated at Wolfram Research, can be accessed and pro-
cessed in a coherent way.

These data functions cover:


math, science, politics, geography, finance, ...

Examples include:
LatticeData,
WeatherData,
Physical and chemical data: ElementData, ChemicalData, IsotopeData, ParticleData, »
Earth and astronomical data: WeatherData, GeodesyData, CityData, CountryData, GeoDistance, AstronomicalData, »
Life science data: GenomeData, GenomeLookup, SequenceAlignment, ProteinData, »
Finance and economic data: FinancialData, CountryData, »
Mathematical data: FiniteGroupData, GraphData, KnotData, LatticeData, PolyhedronData, »
Linguistic data: DictionaryLookup, WordData, ExampleData, »

ProteinData" prot" gives the reference amino acid sequence for the protein prot.
ProteinData" prot", " property" gives the value of the specified property for the protein prot. ‡
22 Data Visualization with Mathematica.03.nb

What Kind of Data and Meta-Data within Collection?

? ElementData

ElementData"name", " property" gives the value of the specified property for the chemical element "name".
ElementDatan, " property" gives the specified property for the nth chemical element. ‡

List the ElementData[] collections:

ElementData

Hydrogen, Helium, Lithium, Beryllium, Boron, Carbon, Nitrogen, Oxygen, Fluorine, Neon, Sodium, Magnesium, Aluminum, 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, Cesium, 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, Protactinium, Uranium, Neptunium, Plutonium, Americium, Curium, Berkelium, Californium, Einsteinium,
Fermium, Mendelevium, Nobelium, Lawrencium, Rutherfordium, Dubnium, Seaborgium, Bohrium, Hassium, Meitnerium,
Darmstadtium, Roentgenium, Ununbium, Ununtrium, Ununquadium, Ununpentium, Ununhexium, Ununseptium, Ununoctium

ElementData1

Hydrogen

LengthElementData

118

ElementData"Properties"

Abbreviation, AbsoluteBoilingPoint, AbsoluteMeltingPoint, AdiabaticIndex, AllotropeNames, AllotropicMultiplicities, AlternateNames,


AlternateStandardNames, AtomicNumber, AtomicRadius, AtomicWeight, Block, BoilingPoint, BrinellHardness, BulkModulus,
CASNumber, Color, CommonCompoundNames, CovalentRadius, CriticalPressure, CriticalTemperature, CrustAbundance,
CrystalStructure, CuriePoint, DecayMode, Density, DiscoveryCountries, DiscoveryYear, ElectricalConductivity, ElectricalType,
ElectronAffinity, ElectronConfiguration, ElectronConfigurationString, Electronegativity, ElectronShellConfiguration,
FusionHeat, GasAtomicMultiplicities, Group, HalfLife, HumanAbundance, IconColor, IonizationEnergies, IsotopeAbundances,
KnownIsotopes, LatticeAngles, LatticeConstants, Lifetime, LiquidDensity, MagneticType, MassMagneticSusceptibility,
MeltingPoint, Memberships, MeteoriteAbundance, MohsHardness, MolarMagneticSusceptibility, MolarVolume, Name,
NeelPoint, NeutronCrossSection, NeutronMassAbsorption, OceanAbundance, Period, Phase, PoissonRatio, QuantumNumbers,
Radioactive, RefractiveIndex, Resistivity, ShearModulus, SolarAbundance, SoundSpeed, SpaceGroupName, SpaceGroupNumber,
SpecificHeat, StableIsotopes, StandardName, SuperconductingPoint, ThermalConductivity, ThermalExpansion, UniverseAbundance,
Valence, VanDerWaalsRadius, VaporizationHeat, VickersHardness, VolumeMagneticSusceptibility, YoungModulus

ElementData can be indexed by full name, number, or abbreviation:


Data Visualization with Mathematica.03.nb 23

ElementData"Hydrogen", "MeltingPoint"

-259.14

ElementData1, "MeltingPoint"

-259.14

ElementData"H", "MeltingPoint"

-259.14

What are the units of Hydrogen's MeltingPoint?

ElementData"H", "MeltingPoint", "Units"

DegreesCelsius

ElementData"H", "MeltingPoint", "UnitsNotation"

°C

Sample Visualization Development

? ListLinePlot

ListLinePlotx1 , y1 , x2 , y2 , … plots a line through specific x and y positions.


ListLinePloty1 , y2 , … plots a line through a list of values, assumed to correspond to x coordinates 1, 2, ….

ListLinePlotlist1 , list2 , … plots several lines. ‡

TableElementDataz, "MeltingPoint", z, 1, 118

-259.14, —, 180.54, 1287., 2075., 3550., -210.1, -218.3, -219.6, -248.59, 97.72, 650., 660.32, 1414., 44.2, 115.21, -101.5, -189.3,
63.38, 842., 1541., 1668., 1910., 1907., 1246., 1538., 1495., 1455., 1084.62, 419.53, 29.76, 938.3, 817., 221., -7.3, -157.36,
39.31, 777., 1526., 1855., 2477., 2623., 2157., 2334., 1964., 1554.9, 961.78, 321.07, 156.6, 231.93, 630.63, 449.51, 113.7, -111.8,
28.44, 727., 920., 798., 931., 1021., 1.1 ´ 103 , 1072., 822., 1313., 1356., 1412., 1474., 1497., 1545., 819., 1663., 2233., 3017.,
3422., 3186., 3033., 2466., 1768.3, 1064.18, -38.83, 304., 327.46, 271.3, 254., 302., -71., —, 7.0 ´ 102 , 1050., 1750., 1572.,
1135., 644., 640., 1176., 1345., 1050., 900., 860., 1527., 827., 827., 1627., —, —, —, —, —, —, —, —, —, —, —, —, —, —, —
24 Data Visualization with Mathematica.03.nb

ListLinePlotTableElementDataz, "MeltingPoint", z, 1, 118

3500

3000

2500

2000

1500

1000

500

20 40 60 80 100

? ListPlot

ListPlotx1 , y1 , x2 , y2 , … plots a list of points with specified x and y coordinates.
ListPloty1 , y2 , … plots points corresponding to a list of values, assumed to correspond to x coordinates 1, 2, ….

ListPlotlist1 , list2 , … plots several lists of points. ‡

ListPlotTableElementDataz, "MeltingPoint", z, 1, 118

3500

3000

2500

2000

1500

1000

500

20 40 60 80 100

TableElementDataz, "MeltingPoint", z, 118

-259.14, —, 180.54, 1287., 2075., 3550., -210.1, -218.3, -219.6, -248.59, 97.72, 650., 660.32, 1414., 44.2, 115.21, -101.5, -189.3,
63.38, 842., 1541., 1668., 1910., 1907., 1246., 1538., 1495., 1455., 1084.62, 419.53, 29.76, 938.3, 817., 221., -7.3, -157.36,
39.31, 777., 1526., 1855., 2477., 2623., 2157., 2334., 1964., 1554.9, 961.78, 321.07, 156.6, 231.93, 630.63, 449.51, 113.7, -111.8,
28.44, 727., 920., 798., 931., 1021., 1.1 ´ 103 , 1072., 822., 1313., 1356., 1412., 1474., 1497., 1545., 819., 1663., 2233., 3017.,
3422., 3186., 3033., 2466., 1768.3, 1064.18, -38.83, 304., 327.46, 271.3, 254., 302., -71., —, 7.0 ´ 102 , 1050., 1750., 1572.,
1135., 644., 640., 1176., 1345., 1050., 900., 860., 1527., 827., 827., 1627., —, —, —, —, —, —, —, —, —, —, —, —, —, —, —

dataMeltingPointElement 
TableElementDataz, "MeltingPoint", ElementDataz, z, 118
Data Visualization with Mathematica.03.nb 25

-259.14 Hydrogen
— Helium
180.54 Lithium
1287. Beryllium
2075. Boron
3550. Carbon
-210.1 Nitrogen
-218.3 Oxygen
-219.6 Fluorine
-248.59 Neon
97.72 Sodium
650. Magnesium
660.32 Aluminum
1414. Silicon
44.2 Phosphorus
115.21 Sulfur
-101.5 Chlorine
-189.3 Argon
63.38 Potassium
842. Calcium
1541. Scandium
1668. Titanium
1910. Vanadium
1907. Chromium
1246. Manganese
1538. Iron
1495. Cobalt
1455. Nickel
1084.62 Copper
419.53 Zinc
29.76 Gallium
938.3 Germanium
817. Arsenic
221. Selenium
-7.3 Bromine
-157.36 Krypton
26 Data Visualization with Mathematica.03.nb

-157.36 Krypton
39.31 Rubidium
777. Strontium
1526. Yttrium
1855. Zirconium
2477. Niobium
2623. Molybdenum
2157. Technetium
2334. Ruthenium
1964. Rhodium
1554.9 Palladium
961.78 Silver
321.07 Cadmium
156.6 Indium
231.93 Tin
630.63 Antimony
449.51 Tellurium
113.7 Iodine
-111.8 Xenon
28.44 Cesium
727. Barium
920. Lanthanum
798. Cerium
931. Praseodymium
1021. Neodymium
1.1 ´ 103 Promethium
1072. Samarium
822. Europium
1313. Gadolinium
1356. Terbium
1412. Dysprosium
1474. Holmium
1497. Erbium
1545. Thulium
819. Ytterbium
1663. Lutetium
2233. Hafnium
3017. Tantalum
3422. Tungsten
3186. Rhenium
3033. Osmium
2466. Iridium
1768.3 Platinum
1064.18 Gold
-38.83 Mercury
304. Thallium
327.46 Lead
Data Visualization with Mathematica.03.nb 27

271.3 Bismuth
254. Polonium
302. Astatine
-71. Radon
— Francium
7.0 ´ 102 Radium
1050. Actinium
1750. Thorium
1572. Protactinium
1135. Uranium
644. Neptunium
640. Plutonium
1176. Americium
1345. Curium
1050. Berkelium
900. Californium
860. Einsteinium
1527. Fermium
827. Mendelevium
827. Nobelium
1627. Lawrencium
— Rutherfordium
— Dubnium
— Seaborgium
— Bohrium
— Hassium
— Meitnerium
— Darmstadtium
— Roentgenium
— Ununbium
— Ununtrium
— Ununquadium
— Ununpentium
— Ununhexium
— Ununseptium
— Ununoctium

? Dimensions

Dimensionsexpr gives a list of the dimensions of expr.


Dimensionsexpr, n gives a list of the dimensions of expr down to level n. ‡

DimensionsdataMeltingPointElement

118, 2

LengthdataMeltingPointElement

118
28 Data Visualization with Mathematica.03.nb

dataMeltingPointElement1

-259.14, Hydrogen

dataMeltingPointElement12

Hydrogen

ListLinePlotTableElementDataz, "MeltingPoint", z, 1, 118

3500

3000

2500

2000

1500

1000

500

20 40 60 80 100
Data Visualization with Mathematica.03.nb 29

TooltipTableElementDataz, "MeltingPoint", z, 1, 118,


ListLinePlot

PlotLabel  "Melting Point vs Atomic Number",


AxesLabel  "Atomic\nNumber", "Melting\nPoint °C",
LabelStyle  DirectiveBlue, Bold, GridLines  Automatic

Melting Point vs Atomic Number

Point °C
Melting

3500

3000

2500

2000

1500

1000

500

20 40 60 80

dataMpBp  TableElementDataz, "MeltingPoint",


ElementDataz, "BoilingPoint", z, 1, 118;
30 Data Visualization with Mathematica.03.nb

ListLinePlotdataMpBp

5000

4000

3000

2000

1000

500 1000 1500 2000 2500 3000 3500

ListPlotdataMpBp

5000

4000

3000

2000

1000

500 1000 1500 2000 2500 3000 3500

The data points can have tool tips with information when the mouse hovers over a data point.

? Tooltip

Tooltipexpr, label displays label as a tooltip while the mouse pointer is in the area where expr is displayed. ‡
Data Visualization with Mathematica.03.nb 31

ListPlotTooltipdataMpBp

5000

4000

3000

2000

1000

500 1000 1500 2000 2500 3000 3500

ElementData"Properties"

Abbreviation, AbsoluteBoilingPoint, AbsoluteMeltingPoint, AdiabaticIndex, AllotropeNames, AllotropicMultiplicities, AlternateNames,


AlternateStandardNames, AtomicNumber, AtomicRadius, AtomicWeight, Block, BoilingPoint, BrinellHardness, BulkModulus,
CASNumber, Color, CommonCompoundNames, CovalentRadius, CriticalPressure, CriticalTemperature, CrustAbundance,
CrystalStructure, CuriePoint, DecayMode, Density, DiscoveryCountries, DiscoveryYear, ElectricalConductivity, ElectricalType,
ElectronAffinity, ElectronConfiguration, ElectronConfigurationString, Electronegativity, ElectronShellConfiguration,
FusionHeat, GasAtomicMultiplicities, Group, HalfLife, HumanAbundance, IconColor, IonizationEnergies, IsotopeAbundances,
KnownIsotopes, LatticeAngles, LatticeConstants, Lifetime, LiquidDensity, MagneticType, MassMagneticSusceptibility,
MeltingPoint, Memberships, MeteoriteAbundance, MohsHardness, MolarMagneticSusceptibility, MolarVolume, Name,
NeelPoint, NeutronCrossSection, NeutronMassAbsorption, OceanAbundance, Period, Phase, PoissonRatio, QuantumNumbers,
Radioactive, RefractiveIndex, Resistivity, ShearModulus, SolarAbundance, SoundSpeed, SpaceGroupName, SpaceGroupNumber,
SpecificHeat, StableIsotopes, StandardName, SuperconductingPoint, ThermalConductivity, ThermalExpansion, UniverseAbundance,
Valence, VanDerWaalsRadius, VaporizationHeat, VickersHardness, VolumeMagneticSusceptibility, YoungModulus

dataMpBp2  TableElementDataz, "MeltingPoint",


ElementDataz, "BoilingPoint", z, 1, 118

-259.14 -252.87
— -268.93
180.54 1342.
1287. 2470.
2075. 4000.
3550. 4027.
-210.1 -195.79
-218.3 -182.9
32 Data Visualization with Mathematica.03.nb

-218.3 -182.9
-219.6 -188.12
-248.59 -246.08
97.72 883.
650. 1090.
660.32 2519.
1414. 2.9 ´ 103
44.2 280.5
115.21 444.72
-101.5 -34.04
-189.3 -185.8
63.38 759.
842. 1484.
1541. 2830.
1668. 3287.
1910. 3407.
1907. 2671.
1246. 2061.
1538. 2861.
1495. 2927.
1455. 2913.
1084.62 2927.
419.53 907.
29.76 2204.
938.3 2820.
817. 614.
221. 685.
-7.3 59.
-157.36 -153.22
39.31 688.
777. 1382.
1526. 3345.
1855. 4409.
2477. 4744.
2623. 4639.
2157. 4265.
2334. 4150.
1964. 3695.
1554.9 2963.
961.78 2162.
321.07 767.
156.6 2072.
231.93 2602.
630.63 1587.
449.51 988.
113.7 184.3
-111.8 -108.
Data Visualization with Mathematica.03.nb 33

-111.8 -108.
28.44 671.
727. 1870.
920. 3464.
798. 3360.
931. 3290.
1021. 3.1 ´ 103
1.1 ´ 103 3.0 ´ 103
1072. 1803.
822. 1527.
1313. 3250.
1356. 3230.
1412. 2567.
1474. 2700.
1497. 2868.
1545. 1950.
819. 1196.
1663. 3402.
2233. 4603.
3017. 5458.
3422. 5555.
3186. 5596.
3033. 5012.
2466. 4428.
1768.3 3825.
1064.18 2856.
-38.83 356.73
304. 1473.
327.46 1749.
271.3 1564.
254. 962.
302. —
-71. -61.7
— —
7.0 ´ 102 1737.
1050. 3200.
1750. 4820.
1572. 4000.
1135. 3927.
644. 4.0 ´ 103
640. 3230.
1176. 2011.
1345. 3110.
1050. —
900. —
860. —
1527.
34 Data Visualization with Mathematica.03.nb

1527. —
827. —
827. —
1627. —
— —
— —
— —
— —
— —
— —
— —
— —
— —
— —
— —
— —
— —
— —
— —

Creating a Dynamic Interactive Manipulative to Huge Data Set

Manipulate

ElementDataz, prop1, ElementDataz, prop2, z, 1, 118,


plotTypeTable

plotType, ListPlot, ListLinePlot,

prop1, ElementData"Properties",
ListLogPlot, ListLogLinearPlot,

prop2, ElementData"Properties"

Data Visualization with Mathematica.03.nb 35

plotType ListPlot ListLinePlot ListLogPlot ListLogLinearPlot

prop1 AtomicNumber

prop2 AtomicRadius

300

250

200

150

100

20 40 60 80

Capabilities - Only the Beginning

Plot the closing prices for Google stock since its initial public offering on August 19, 2004.

DateListPlot
TooltipFinancialData"GOOG", "August 19 2004", Joined  True

700

600

500

400

300

200

100
2005 2006 2007 2008 2009 2010

This creates a plot comparing the closing stock price over the year 2006 for three companies: General Electric, Akamai, and
Microsoft.
36 Data Visualization with Mathematica.03.nb

FinancialData"GE", "2006", FinancialData"AKAM", "2006",


DateListPlotTooltip

FinancialData"MSFT", "2006", Joined  True

60

50

40

30

20

10

2006 2007 2008 2009 2010

AstronomicalData"Earth", "Image"

AstronomicalData, "Name" &  AstronomicalData"Planet"


TooltipAstronomicalData, "Image",

Make a graphic of solar system orbit paths with tooltips displaying images of each planet.
Data Visualization with Mathematica.03.nb 37

AstronomicalData, "Image" & 


Graphics3DLightGray, TooltipAstronomicalData, "OrbitPath",

AstronomicalData"Planet", Background  Black

Varying distance of planets from Earth in 2009:

AstronomicalData"Earth", "Distance", "Units"

Meters

DateListPlot

"Distance", DateList2009, 1, i, i, 1, 365.25, 10,


TooltipTableDateList2009, 1, i, AstronomicalData,

 &  "Mercury", "Venus", "Mars", "Jupiter", "Saturn",


Joined  True, GridLines  Automatic

1.5 ´ 1012

1.0 ´ 1012

5.0 ´ 1011

0
Jan Apr Jul Oct Jan
38 Data Visualization with Mathematica.03.nb

ProteinData"SP1", "MoleculePlot"
Import a PDB file.

Import"ExampleData1PPT.pdb"
Import a PDB file by setting various options.

Import"ExampleData1PPT.pdb", "PDB", Background  GrayLevel0.15,


ImageSize  Medium, "Rendering"  "Wireframe"
Get the title of this PDB file.

Import"ExampleData1PPT.pdb", "PDB", "Title"

X-RAY ANALYSIS 1.4-ANGSTROMS RESOLUTION OF


AVIAN PANCREATIC POLYPEPTIDE. SMALL GLOBULAR PROTEIN HORMONE

Get the name of the organism referenced in this file.

"PDB", "Organism", "DepositionDate"


Import"ExampleData1PPT.pdb",

MOL_ID ® 1, ORGANISM_SCIENTIFIC® MELEAGRIS GALLOPAVO, 1981, 1, 16, 0, 0, 0.

Import the residue sequence.

Import"ExampleData1PPT.pdb", "Residues"

 Gly Pro Ser Gln Pro Thr Tyr Pro Gly Asp Asp Ala Pro Val Glu Asp Leu Ile Arg Phe Tyr Asp Asn Leu Gln Gln

Import a 3D molecule model as a ball-and-stick model.

Import"ExampleDataaspirin.mol"

Show the bonds of the same molecule using spacefilling rendering.

Import"ExampleDataaspirin.mol", "Rendering"  "Spacefilling"

Import a 3D molecule model as a wireframe model.


Data Visualization with Mathematica.03.nb 39

Import a 3D molecule model as a wireframe model.

Import"ExampleDataaspirin.mol", "Rendering"  "Wireframe"

When importing a molfile that contains a 2 D representation of a molecule, Mathematica automatically renders it as a
chemical structure diagram.

Import "ExampleDatafluoxetine.mol"

This gives the atom types and their 2D coordinates for the structure diagram.

"VertexTypes", "VertexCoordinates"
Import"ExampleDatafluoxetine.mol",

-98.28, 75.86 -98.28, -7.24 -25.86, 117.59 -170.69, 117.59 -171.03, -48.97 -26.21, -48.97 46.21, 75.86 -242.41
C C O C C C C C

This creates a molfile from the previous output.

molstr 
ExportString , "MOL", "VertexTypes", "VertexCoordinates"
40 Data Visualization with Mathematica.03.nb

Created by Wolfram Mathematica 7.0 : www.wolfram.com

22 0 0 0 0 999 V2000

-0.9828 0.7586 0.0000 C 0 0 0 0 0 0 0 0 0

-0.9828 -0.0724 0.0000 C 0 0 0 0 0 0 0 0 0

-0.2586 1.1759 0.0000 O 0 0 0 0 0 0 0 0 0

-1.7069 1.1759 0.0000 C 0 0 0 0 0 0 0 0 0

-1.7103 -0.4897 0.0000 C 0 0 0 0 0 0 0 0 0

-0.2621 -0.4897 0.0000 C 0 0 0 0 0 0 0 0 0

0.4621 0.7586 0.0000 C 0 0 0 0 0 0 0 0 0

-2.4241 0.7621 0.0000 C 0 0 0 0 0 0 0 0 0

-1.7103 -1.3241 0.0000 C 0 0 0 0 0 0 0 0 0

-0.2621 -1.3241 0.0000 C 0 0 0 0 0 0 0 0 0

0.4621 -0.0724 0.0000 C 0 0 0 0 0 0 0 0 0

1.1828 1.1759 0.0000 C 0 0 0 0 0 0 0 0 0

-3.1483 1.1793 0.0000 N 0 0 0 0 0 0 0 0 0

-0.9828 -1.7414 0.0000 C 0 0 0 0 0 0 0 0 0

1.1793 -0.4897 0.0000 C 0 0 0 0 0 0 0 0 0

1.9035 0.7586 0.0000 C 0 0 0 0 0 0 0 0 0

-3.8690 0.7621 0.0000 C 0 0 0 0 0 0 0 0 0

1.9035 -0.0759 0.0000 C 0 0 0 0 0 0 0 0 0

2.6241 -0.4931 0.0000 C 0 0 0 0 0 0 0 0 0

3.4000 -0.8690 0.0000 F 0 0 0 0 0 0 0 0 0

2.9724 0.0966 0.0000 F 0 0 0 0 0 0 0 0 0

2.2172 -1.1621 0.0000 F 0 0 0 0 0 0 0 0 0

M END
Data Visualization with Mathematica.03.nb 41

ImportStringmolstr, "MOL", "VertexTypes"

C, C, O, C, C, C, C, C, C, C, C, C, N, C, C, C, C, C, C, F, F, F

ImportStringmolstr, "MOL", "VertexCoordinates"

-98.28 75.86
-98.28 -7.24
-25.86 117.59
-170.69 117.59
-171.03 -48.97
-26.21 -48.97
46.21 75.86
-242.41 76.21
-171.03 -132.41
-26.21 -132.41
46.21 -7.24
118.28 117.59
-314.83 117.93
-98.28 -174.14
117.93 -48.97
190.35 75.86
-386.9 76.21
190.35 -7.59
262.41 -49.31
340. -86.9
297.24 9.66
221.72 -116.21

Initializations

sizeImageNotebook  200;

Potrebbero piacerti anche