Top Banner
Graphical Excellence Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II
31
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

Graphical ExcellenceGraphical ExcellenceCMSC 120: Visualizing Information2/7/08 Lecture Part II

Page 2: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

Graphical displays should:Graphical displays should: Show the data

Induce the viewer to think about substance, not◦ Methodology◦ Design◦ Technology

Tell the truth

Make the complex simple

Serve a clear purpose

Reveal the data

Page 3: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

DataData

Page 4: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

VisualizationVisualization

Page 5: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

Fate of Napoleon’s ArmyFate of Napoleon’s Army

Page 6: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

Principles of Graphics Principles of Graphics ExcellenceExcellenceMatter of substance, statistics,

and design

Communicate complex ideas with clarity, precision, and efficiency

Give viewer the greatest number of ideas in the shortest time, with the least ink, in the smallest space

Page 7: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

A Matter of Substance and A Matter of Substance and StatisticsStatisticsCMSC 120: Visualizing Information2/7/08 Lecture: Part II

Page 8: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

DataData

Page 9: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

Samples and PopulationsSamples and PopulationsLaw of Large Numbers:

◦ The more observations we have, the greater the understanding we have of the true behavior of a system

Sample: set of observations

Population: all possible observations

Page 10: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

DistributionDistributionArrangement of the set of

possible solutions along a number line

Page 11: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

Statistical Properties of Statistical Properties of DataData

Mean: average of all the values (expected value) Median: middle value Mode: value that occurs most often Variance: spread away from the mean Standard Deviation: square root of the variance

MaxMin

Page 12: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

Relational StatisticsRelational Statistics

Covariance: spread of values in multiple dimensionsCorrelation: how well one measure predicts another

Page 13: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

Pylab and Python Pylab and Python StatisticsStatisticsmean(<DATA>)median(<DATA>)var(<DATA>)std(<DATA>)correlate(<DATA>)corrcoeff(<DATA>)cov(<DATA>)

Page 14: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

Sprechen de Python?Sprechen de Python?CMSC 120: Visualizing Information2/7/08: Lecture Part III

Page 15: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

Blocks of codeBlocks of code>>> def plotData():

plot(Year, Marijuana)

show()

xlabel('Year')

ylabel('Percentage')

title('Marijuana Drug Use')

>>> def plotData():

plot(Year, Marijuana)

show()

xlabel('Year')

ylabel('Percentage')

title('Marijuana Drug Use')

Function: a block of related code that performs a single task

defplotData: a user-defined “keyword”

Page 16: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

Running a FunctionRunning a Function>>> plotData()

>>> plotData()

Page 17: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

ParametersParameters>>> def plotData():

plot(Year, Marijuana)

show()

xlabel('Year')

ylabel('Percentage')

title('Marijuana Drug Use')

>>> def plotData():

plot(Year, Marijuana)

show()

xlabel('Year')

ylabel('Percentage')

title('Marijuana Drug Use')

>>> def plotData2():

plot(Year, Heroin)

show()

xlabel('Year')

ylabel('Percentage')

title('Heroin Drug Use')

>>> def plotData2():

plot(Year, Heroin)

show()

xlabel('Year')

ylabel('Percentage')

title('Heroin Drug Use')

Page 18: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

>>> def plotData():

plot(Year, Marijuana)

show()

xlabel('Year')

ylabel('Percentage')

title('Marijuana Drug Use')

>>> def plotData():

plot(Year, Marijuana)

show()

xlabel('Year')

ylabel('Percentage')

title('Marijuana Drug Use')

ParametersParameters

Input

Flexibility

>>> def plotData(data, name):

plot(Year, data)

show()

xlabel('Year')

ylabel('Percentage')

title(name + ' Drug Use')

>>> def plotData(data, name):

plot(Year, data)

show()

xlabel('Year')

ylabel('Percentage')

title(name + ' Drug Use')

Page 19: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

ParametersParameters>>> plotData(Marijuana, 'Marijuana')

>>> plotData(Marijuana, 'Marijuana')

Page 20: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

ParametersParameters>>> plotData(Heroin, 'Heroin')

>>> plotData(Heroin, 'Heroin')

Page 21: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

FunctionsFunctionsdef <FUNCTION NAME> (<PARAMTERS>): <SOMETHING>

: <SOMETHING>

Page 22: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

Running a FunctionRunning a Function>>> plotData()

>>> plotData()

Traceback (most recent call last): File "<pyshell#5>", line 1, in

<module> plotData()NameError: name 'plotData' is not

defined

Page 23: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

ModulesModulesType the function definition in a

text fileSave SOURCE CODE

Page 24: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

ModulesModules

Type the function definition in a text fileSave SOURCE CODE

# File: plotdata.py

# Purpose: A useful plotting function

# Author: Me

# Import Pylab

from pylab import *

# Import Data

from DrugData import *

# Define the function

def plotData(data, name):

plot(Year, data)

show()

xlabel('Year')

ylabel('Percentage')

title(name + ' Drug Use')

# File: plotdata.py

# Purpose: A useful plotting function

# Author: Me

# Import Pylab

from pylab import *

# Import Data

from DrugData import *

# Define the function

def plotData(data, name):

plot(Year, data)

show()

xlabel('Year')

ylabel('Percentage')

title(name + ' Drug Use')

Page 25: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

CommentsComments

AnnotateExplainIdentify

# File: plotdata.py

# Purpose: A useful plotting function

# Author: Me

# File: plotdata.py

# Purpose: A useful plotting function

# Author: Me

Page 26: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

Import StatementImport Statement

Load modules into interpreter memory

from <MODULE> import <SOMETHING>from DrugData import Marijuana

# Import Pylab

from pylab import *

# Import Data

from DrugData import *

# Import Pylab

from pylab import *

# Import Data

from DrugData import *

Page 27: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

StringsStrings

A list of charactersIndicated by '<SOMETHING>'

String concatenation: 'a' + 'b' 'ab'

title(name + ' Drug Use')

title(name + ' Drug Use')

Page 28: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

Function DefinitionFunction Definition

# Define the function

def plotData(data, name):

plot(Year, data)

show()

xlabel('Year')

ylabel('Percentage')

title(name + ' Drug Use')

# Define the function

def plotData(data, name):

plot(Year, data)

show()

xlabel('Year')

ylabel('Percentage')

title(name + ' Drug Use')

You can define more than function in a module

Page 29: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

Running a Function from a Running a Function from a ModuleModule>>> from plotData import *

>>> plotData(Heroin, 'Heroin')

>>> from plotData import *

>>> plotData(Heroin, 'Heroin')

Page 30: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

Return ValuesReturn Values

Output

return <SOMETHING>Function exits immediately after

executing

>>> def average(data):

# function uses “average”

# instead of “mean”

return mean(data)

>>> def average(data):

# function uses “average”

# instead of “mean”

return mean(data)

Page 31: Graphical Excellence CMSC 120: Visualizing Information 2/7/08 Lecture Part II.

Module Syntax: Module Syntax: IndentationIndentation>>> def plotData():

plot(Year, Marijuana)

show()

xlabel('Year')

ylabel('Percentage')

title('Marijuana Drug Use')

>>> def plotData():

plot(Year, Marijuana)

show()

xlabel('Year')

ylabel('Percentage')

title('Marijuana Drug Use')

File "<pyshell#7>", line 3 show() ^IndentationError: unexpected indent