SlideShare a Scribd company logo
1 of 20
Computer Science 151
An introduction to the art of
computing
Graphing Lecture 2
Rudy Martinez
Graphing Libraries
• Matplotlib is a Python 2D plotting library which produces publication
quality figures in a variety of hardcopy formats and interactive
environments across platforms.
• De Facto standard for general graphing
• Bokeh is an interactive visualization library that targets modern web
browsers for presentation.
• Designed for high performance over large datasets.
• Seaborn is a Python data visualization library based on matplotlib. It
provides a high-level interface for drawing attractive and informative
statistical graphics.
• Many others …
4/8/2019CS151SP19
Pyplot
• Pyplot is a collection of command style functions that make
matplotlib work like MATLAB.
Code Example:
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.ylabel(“Numbers’)
plt.show()
4/8/2019CS151SP19
Plotting Functions
Function Description
pyplot.bar(x-value, y-value)
pyplot.bar([x-values], [y-values])
Plots a single bar on the graph or multiple bars when the x- and y-values are
provided as lists.
pyplot.plot([x-coords], [y-coords])
pyplot.plot([x-coords], [y-coords], format)
Plots a line graph. The color and style of the line can be specified with a format
string.
pyplot.grid("on") Adds a grid to the graph.
pyplot.xlim(min, max)
pyplot.ylim(min, max)
Sets the range of x- or y-values shown on the graph.
pyplot.title(text) Adds a title to the graph.
pyplot.xlabel(text)
pyplot.ylabel(text)
Adds a label below the x-axis or to the left of the y-axis.
pyplot.legend([label1, label2, ...]) Adds a legend for multiple lines.
pyplot.xticks([x-coord1, x-coord2, ...], [label1, label2, ...]) Adds labels below the tick marks along the x-axis.
pyplot.xticks([x-coord1, x-coord2, ...], [label1, label2, ...]) Adds labels to the left of the tick marks along the y-axis.
pyplot.show() Displays the plot.
4/8/2019CS151SP19
Creating a Line Graph
• The following line allows us to call our plot plt instead of
matplotlib.pyplot
Import matplotlib.pyplot as plt
# Set Plot Size (optional)
plt.figure(figsize(20,10))
plt.style.use(‘ggplot’)
4/8/2019CS151SP19
Example Cont.
plt.plot(X,Y, color=‘red’, label=‘num’)
_______________________
plt.plot(yearList, Avg_Tmax, label=‘Tmax’)
plt.plot(yearList, Avg_Tmin, label=‘Tmin’)
• plt is our plot
• .plot() is a function that will plot
a line chart.
• X,Y is the data to be plotted,
usually a list
• Color is to manually control the
color of the plotted line
• Label will add the given string to
the Legend if selected.
4/8/2019CS151SP19
Example Cont.
plt.plot(yearList, Avg_Tmax, label=‘Tmax’)
plt.plot(yearList, Avg_Tmin, label=‘Tmin’)
• yearList is my list of years, I
called .keys() on my dictionary
and it yields a list of years.
• Avg_Tmax is my list of Tmax
values from my averagedata.csv
• Avg_Tmin is also from the Tmin
from average data.csv.
• Note we are not graphing
standard deviation.
4/8/2019CS151SP19
Example Cont.
plt.plot(yearList, Avg_Tmax, label=‘Tmax’)
plt.plot(yearList, Avg_Tmin, label=‘Tmin’)
plt.plot(yearList, plotAvgMax, label=‘Max Avg’)
Plt.plot(yearList, plotAvgMin, label=‘Min Avg’)
• plotAvgMax is the average of all
the years plotted on the graph.
• It’s a single value, but the way
graphing works.
4/8/2019CS151SP19
List Comprehension
• We need to get a single value in to a list that is of size N.
• We could do a for loop
plotAvgMax = []
for i in range(0, len(AVGDATA), 1):
plotAvgMax = avgMax
• Where plotAvgMax is given a copy of the avgMax in each element.
• avgMax is the sum of all the yearly averages divided by the number of
values. (typical arithmetic mean)
4/8/2019CS151SP19
List Comprehension
• We need to get a single value in to a list that is of size N.
• The most pythonic way is to use a list comprehension:
plotAvgMax = [avgMax for I in range(len(AVGDATA))]
• This then gives us what we wanted.
4/8/2019CS151SP19
Back to graphing
# Set Title
plt.title(‘Albuquerque, NM NOAA Values’)
# Set Axis
plt.xlabel(‘Year’)
plt.ylabel(‘Temperature (F)’)
# Add a legend
plt.legend()
# Save the file for your report
plt.savefig(‘Homework2cplot.png’)
# Show the plot
plt.show()
4/8/2019CS151SP19
Algorithm
• Create Variables
• Dictionary to hold Year: Tmax
• Dictionary to hold Year: Tmin
• Dictionary to hold Average data from averagedata.csv( year:[tmax, tmin] )
• List to hold all the Tmax values from homework2.csv
• List to hold all the Tmin values from homeworlk2.csv
4/8/2019CS151SP19
Algorithm
• Load Data from homework2.csv into my two dictionaries
• For every year
• If the year has not changed:
• Append Tmax to list
• Append Tmin to list
• Else the year has changed:
• Update Year: Tmax list (deep copy) to a Dictionary (Max)
• Update Year: Tmin list (deep copy) to a Dictionary (Min)
• Max list clear
• Min List clear
• Set new year
4/8/2019CS151SP19
Algorithm
• Need to load data from averagedata.csv into dictionary.
• For every row in averagedata:
• Update in Dictionary Year: [Tmax, Tmin]  row[0]: [row[1], row[2]]
• For graphing set a list of Avg_Tmax.append(float(row[1])
• For graphing set a list of Avg_Tmin.append(float(row[2])
• Sum Tmax values
• Sum Tmin values
• Create avgMax = sumTmax/len(Avg_Tmax)
• Create avgMin = sumTmin/len(Avg_Tmin)
4/8/2019CS151SP19
Algorithm
• Now manual calc of Std Dev.
• For every year in Tmax dictionary (from averagedata.csv)
• For every item in Tmax list (from homework2.csv)
• Max_sum += math.pow((item – average tmax value),2)
• Max sigma = math.sqrt(max_sum / (length of Tmax list))
• Update a new dictionary with {row: max sigma}
• Do the same for Tmin
• You should now have two dictionaries, Tmax, Tmin with year: sigma
4/8/2019CS151SP19
Algorithm
• Calculate std deviation using statistics package
• For every year in list of Tmax daily values
• Max sigma.update( year: statistics.stdev(Tmax[day])
• Min sigma.update( year: statistics.stdev(Tmin[day}
• Remember stddev takes a list, earlier in one of the for loops you
should have created a list of every TMAX value and every TMIN value
and create a TMAX dictionary with year: [list of tmax values] and
TMIN dictionary with year: [list of tmin values]
4/8/2019CS151SP19
Algorithm
• Now create the graph.
• plt.plot(yearList, Avg_Tmax, label='TMax')
• plt.plot(yearList, Avg_Tmin, label='TMin')
• plt.plot(yearList, plotAvgMax, label='Max Average')
• plt.plot(yearList, plotAvgMin, label='Min Average’)
• Here yearList is easy Tmax Dictionary.keys()
• Avg_Tmax/Tmin were created when we read in the for loop for
average data.
• Use given list comprehension to generate plotAvgMax/Min
4/8/2019CS151SP19
Algorithm
• Write Report!
• What is the data?
• Format
• What did you do to the data? Any formatting or cleaning?
• A short description of your methodology:
• I used a program to analyze the above data ….
• Print the graph in the report
• What is the graph telling you about 25 years of temperature data?
• You have the standard deviation, can you tell me what that number means in terms of
temperature year to year?
• The temperatures are just numbers, what do they really mean in terms of subjective
assessment to you!
4/8/2019CS151SP19
Turn in
• Homework2c.py file to learn.
• Report in pdf format.
• No longer than 1 page.
4/8/2019CS151SP19
Final Project
• You will receive a data file (csv format) of Sunspot data.
• Utilizing what you have learned in Homework2 you will answer the
following questions in a report:
• Are there any discernable cycles for sunspots?
• If yes, what is this cycle?
• Can you prove it with a graph?
• What are the statistics for each cycle?
• Mean number per cycle
• Std deviation per cycle
4/8/2019CS151SP19

More Related Content

What's hot

Too Much Data? - Just Sample, Just Hash, ...
Too Much Data? - Just Sample, Just Hash, ...Too Much Data? - Just Sample, Just Hash, ...
Too Much Data? - Just Sample, Just Hash, ...Andrii Gakhov
 
Hive query optimization infinity
Hive query optimization infinityHive query optimization infinity
Hive query optimization infinityShashwat Shriparv
 
Mining big data streams with APACHE SAMOA by Albert Bifet
Mining big data streams with APACHE SAMOA by Albert BifetMining big data streams with APACHE SAMOA by Albert Bifet
Mining big data streams with APACHE SAMOA by Albert BifetJ On The Beach
 
Mining Big Data Streams with APACHE SAMOA
Mining Big Data Streams with APACHE SAMOAMining Big Data Streams with APACHE SAMOA
Mining Big Data Streams with APACHE SAMOAAlbert Bifet
 
Ernest: Efficient Performance Prediction for Advanced Analytics on Apache Spa...
Ernest: Efficient Performance Prediction for Advanced Analytics on Apache Spa...Ernest: Efficient Performance Prediction for Advanced Analytics on Apache Spa...
Ernest: Efficient Performance Prediction for Advanced Analytics on Apache Spa...Spark Summit
 
Streaming Algorithms
Streaming AlgorithmsStreaming Algorithms
Streaming AlgorithmsJoe Kelley
 
Hadoop combiner and partitioner
Hadoop combiner and partitionerHadoop combiner and partitioner
Hadoop combiner and partitionerSubhas Kumar Ghosh
 
Mikio Braun – Data flow vs. procedural programming
Mikio Braun – Data flow vs. procedural programming Mikio Braun – Data flow vs. procedural programming
Mikio Braun – Data flow vs. procedural programming Flink Forward
 
Online learning with structured streaming, spark summit brussels 2016
Online learning with structured streaming, spark summit brussels 2016Online learning with structured streaming, spark summit brussels 2016
Online learning with structured streaming, spark summit brussels 2016Ram Sriharsha
 
Albert Bifet – Apache Samoa: Mining Big Data Streams with Apache Flink
Albert Bifet – Apache Samoa: Mining Big Data Streams with Apache FlinkAlbert Bifet – Apache Samoa: Mining Big Data Streams with Apache Flink
Albert Bifet – Apache Samoa: Mining Big Data Streams with Apache FlinkFlink Forward
 
Big Data Analysis with Crate and Python
Big Data Analysis with Crate and PythonBig Data Analysis with Crate and Python
Big Data Analysis with Crate and PythonMatthias Wahl
 
Pranav Bahl & Jonathan Stacks - Robust Automated Forecasting in Python and R
Pranav Bahl & Jonathan Stacks - Robust Automated Forecasting in Python and RPranav Bahl & Jonathan Stacks - Robust Automated Forecasting in Python and R
Pranav Bahl & Jonathan Stacks - Robust Automated Forecasting in Python and RPyData
 
Mining high speed data streams: Hoeffding and VFDT
Mining high speed data streams: Hoeffding and VFDTMining high speed data streams: Hoeffding and VFDT
Mining high speed data streams: Hoeffding and VFDTDavide Gallitelli
 
Artificial intelligence and data stream mining
Artificial intelligence and data stream miningArtificial intelligence and data stream mining
Artificial intelligence and data stream miningAlbert Bifet
 
5.1 mining data streams
5.1 mining data streams5.1 mining data streams
5.1 mining data streamsKrish_ver2
 
Nathaniel Cook - Forecasting Time Series Data at scale with the TICK stack
Nathaniel Cook - Forecasting Time Series Data at scale with the TICK stackNathaniel Cook - Forecasting Time Series Data at scale with the TICK stack
Nathaniel Cook - Forecasting Time Series Data at scale with the TICK stackPyData
 
Mapreduce total order sorting technique
Mapreduce total order sorting techniqueMapreduce total order sorting technique
Mapreduce total order sorting techniqueUday Vakalapudi
 

What's hot (20)

Too Much Data? - Just Sample, Just Hash, ...
Too Much Data? - Just Sample, Just Hash, ...Too Much Data? - Just Sample, Just Hash, ...
Too Much Data? - Just Sample, Just Hash, ...
 
Hive query optimization infinity
Hive query optimization infinityHive query optimization infinity
Hive query optimization infinity
 
Mining big data streams with APACHE SAMOA by Albert Bifet
Mining big data streams with APACHE SAMOA by Albert BifetMining big data streams with APACHE SAMOA by Albert Bifet
Mining big data streams with APACHE SAMOA by Albert Bifet
 
04 pig data operations
04 pig data operations04 pig data operations
04 pig data operations
 
Mining Big Data Streams with APACHE SAMOA
Mining Big Data Streams with APACHE SAMOAMining Big Data Streams with APACHE SAMOA
Mining Big Data Streams with APACHE SAMOA
 
Ernest: Efficient Performance Prediction for Advanced Analytics on Apache Spa...
Ernest: Efficient Performance Prediction for Advanced Analytics on Apache Spa...Ernest: Efficient Performance Prediction for Advanced Analytics on Apache Spa...
Ernest: Efficient Performance Prediction for Advanced Analytics on Apache Spa...
 
Streaming Algorithms
Streaming AlgorithmsStreaming Algorithms
Streaming Algorithms
 
Hadoop combiner and partitioner
Hadoop combiner and partitionerHadoop combiner and partitioner
Hadoop combiner and partitioner
 
Mikio Braun – Data flow vs. procedural programming
Mikio Braun – Data flow vs. procedural programming Mikio Braun – Data flow vs. procedural programming
Mikio Braun – Data flow vs. procedural programming
 
Hadoop job chaining
Hadoop job chainingHadoop job chaining
Hadoop job chaining
 
Online learning with structured streaming, spark summit brussels 2016
Online learning with structured streaming, spark summit brussels 2016Online learning with structured streaming, spark summit brussels 2016
Online learning with structured streaming, spark summit brussels 2016
 
Albert Bifet – Apache Samoa: Mining Big Data Streams with Apache Flink
Albert Bifet – Apache Samoa: Mining Big Data Streams with Apache FlinkAlbert Bifet – Apache Samoa: Mining Big Data Streams with Apache Flink
Albert Bifet – Apache Samoa: Mining Big Data Streams with Apache Flink
 
Big Data Analysis with Crate and Python
Big Data Analysis with Crate and PythonBig Data Analysis with Crate and Python
Big Data Analysis with Crate and Python
 
Pranav Bahl & Jonathan Stacks - Robust Automated Forecasting in Python and R
Pranav Bahl & Jonathan Stacks - Robust Automated Forecasting in Python and RPranav Bahl & Jonathan Stacks - Robust Automated Forecasting in Python and R
Pranav Bahl & Jonathan Stacks - Robust Automated Forecasting in Python and R
 
Mining high speed data streams: Hoeffding and VFDT
Mining high speed data streams: Hoeffding and VFDTMining high speed data streams: Hoeffding and VFDT
Mining high speed data streams: Hoeffding and VFDT
 
Artificial intelligence and data stream mining
Artificial intelligence and data stream miningArtificial intelligence and data stream mining
Artificial intelligence and data stream mining
 
Group functions
Group functionsGroup functions
Group functions
 
5.1 mining data streams
5.1 mining data streams5.1 mining data streams
5.1 mining data streams
 
Nathaniel Cook - Forecasting Time Series Data at scale with the TICK stack
Nathaniel Cook - Forecasting Time Series Data at scale with the TICK stackNathaniel Cook - Forecasting Time Series Data at scale with the TICK stack
Nathaniel Cook - Forecasting Time Series Data at scale with the TICK stack
 
Mapreduce total order sorting technique
Mapreduce total order sorting techniqueMapreduce total order sorting technique
Mapreduce total order sorting technique
 

Similar to CS 151 Graphing lecture

R programming slides
R  programming slidesR  programming slides
R programming slidesPankaj Saini
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine LearningAmanBhalla14
 
Week-3 – System RSupplemental material1Recap •.docx
Week-3 – System RSupplemental material1Recap •.docxWeek-3 – System RSupplemental material1Recap •.docx
Week-3 – System RSupplemental material1Recap •.docxhelzerpatrina
 
Cost-Based Optimizer in Apache Spark 2.2 Ron Hu, Sameer Agarwal, Wenchen Fan ...
Cost-Based Optimizer in Apache Spark 2.2 Ron Hu, Sameer Agarwal, Wenchen Fan ...Cost-Based Optimizer in Apache Spark 2.2 Ron Hu, Sameer Agarwal, Wenchen Fan ...
Cost-Based Optimizer in Apache Spark 2.2 Ron Hu, Sameer Agarwal, Wenchen Fan ...Databricks
 
Basic concept of MATLAB.ppt
Basic concept of MATLAB.pptBasic concept of MATLAB.ppt
Basic concept of MATLAB.pptaliraza2732
 
UNIT_4_data visualization.pptx
UNIT_4_data visualization.pptxUNIT_4_data visualization.pptx
UNIT_4_data visualization.pptxBhagyasriPatel2
 
Cost-Based Optimizer in Apache Spark 2.2
Cost-Based Optimizer in Apache Spark 2.2 Cost-Based Optimizer in Apache Spark 2.2
Cost-Based Optimizer in Apache Spark 2.2 Databricks
 
Exploratory data analysis using r
Exploratory data analysis using rExploratory data analysis using r
Exploratory data analysis using rTahera Shaikh
 
Python-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdfPython-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdfssuser598883
 
Lesson 2 data preprocessing
Lesson 2   data preprocessingLesson 2   data preprocessing
Lesson 2 data preprocessingAbdurRazzaqe1
 
Query Compilation in Impala
Query Compilation in ImpalaQuery Compilation in Impala
Query Compilation in ImpalaCloudera, Inc.
 
Enhancing Spark SQL Optimizer with Reliable Statistics
Enhancing Spark SQL Optimizer with Reliable StatisticsEnhancing Spark SQL Optimizer with Reliable Statistics
Enhancing Spark SQL Optimizer with Reliable StatisticsJen Aman
 

Similar to CS 151 Graphing lecture (20)

CS151 Deep copy
CS151 Deep copyCS151 Deep copy
CS151 Deep copy
 
R programming slides
R  programming slidesR  programming slides
R programming slides
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine Learning
 
Week-3 – System RSupplemental material1Recap •.docx
Week-3 – System RSupplemental material1Recap •.docxWeek-3 – System RSupplemental material1Recap •.docx
Week-3 – System RSupplemental material1Recap •.docx
 
Cost-Based Optimizer in Apache Spark 2.2 Ron Hu, Sameer Agarwal, Wenchen Fan ...
Cost-Based Optimizer in Apache Spark 2.2 Ron Hu, Sameer Agarwal, Wenchen Fan ...Cost-Based Optimizer in Apache Spark 2.2 Ron Hu, Sameer Agarwal, Wenchen Fan ...
Cost-Based Optimizer in Apache Spark 2.2 Ron Hu, Sameer Agarwal, Wenchen Fan ...
 
Basic concept of MATLAB.ppt
Basic concept of MATLAB.pptBasic concept of MATLAB.ppt
Basic concept of MATLAB.ppt
 
UNIT_4_data visualization.pptx
UNIT_4_data visualization.pptxUNIT_4_data visualization.pptx
UNIT_4_data visualization.pptx
 
CS 151 homework2a
CS 151 homework2aCS 151 homework2a
CS 151 homework2a
 
Aggregate.pptx
Aggregate.pptxAggregate.pptx
Aggregate.pptx
 
Cost-Based Optimizer in Apache Spark 2.2
Cost-Based Optimizer in Apache Spark 2.2 Cost-Based Optimizer in Apache Spark 2.2
Cost-Based Optimizer in Apache Spark 2.2
 
Exploratory data analysis using r
Exploratory data analysis using rExploratory data analysis using r
Exploratory data analysis using r
 
Python for data analysis
Python for data analysisPython for data analysis
Python for data analysis
 
Lecture 9.pptx
Lecture 9.pptxLecture 9.pptx
Lecture 9.pptx
 
Python-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdfPython-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdf
 
Python for Data Science
Python for Data SciencePython for Data Science
Python for Data Science
 
Lesson 2 data preprocessing
Lesson 2   data preprocessingLesson 2   data preprocessing
Lesson 2 data preprocessing
 
Query Compilation in Impala
Query Compilation in ImpalaQuery Compilation in Impala
Query Compilation in Impala
 
Lecture5.pptx
Lecture5.pptxLecture5.pptx
Lecture5.pptx
 
Enhancing Spark SQL Optimizer with Reliable Statistics
Enhancing Spark SQL Optimizer with Reliable StatisticsEnhancing Spark SQL Optimizer with Reliable Statistics
Enhancing Spark SQL Optimizer with Reliable Statistics
 
iPython
iPythoniPython
iPython
 

More from Rudy Martinez

More from Rudy Martinez (16)

CS 151Exploration of python
CS 151Exploration of pythonCS 151Exploration of python
CS 151Exploration of python
 
CS 151 Classes lecture 2
CS 151 Classes lecture 2CS 151 Classes lecture 2
CS 151 Classes lecture 2
 
CS 151 Classes lecture
CS 151 Classes lectureCS 151 Classes lecture
CS 151 Classes lecture
 
CS 151 Standard deviation lecture
CS 151 Standard deviation lectureCS 151 Standard deviation lecture
CS 151 Standard deviation lecture
 
CS 151 Midterm review
CS 151 Midterm reviewCS 151 Midterm review
CS 151 Midterm review
 
Cs 151 dictionary writer
Cs 151 dictionary writerCs 151 dictionary writer
Cs 151 dictionary writer
 
CS 151 dictionary objects
CS 151 dictionary objectsCS 151 dictionary objects
CS 151 dictionary objects
 
CS 151 CSV output
CS 151 CSV outputCS 151 CSV output
CS 151 CSV output
 
CS 151 Date time lecture
CS 151 Date time lectureCS 151 Date time lecture
CS 151 Date time lecture
 
CS151 FIle Input and Output
CS151 FIle Input and OutputCS151 FIle Input and Output
CS151 FIle Input and Output
 
CS151 Functions lecture
CS151 Functions lectureCS151 Functions lecture
CS151 Functions lecture
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture01
Lecture01Lecture01
Lecture01
 
Lecture02
Lecture02Lecture02
Lecture02
 
Lecture03
Lecture03Lecture03
Lecture03
 
Lecture01
Lecture01Lecture01
Lecture01
 

Recently uploaded

Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 

Recently uploaded (20)

OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 

CS 151 Graphing lecture

  • 1. Computer Science 151 An introduction to the art of computing Graphing Lecture 2 Rudy Martinez
  • 2. Graphing Libraries • Matplotlib is a Python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. • De Facto standard for general graphing • Bokeh is an interactive visualization library that targets modern web browsers for presentation. • Designed for high performance over large datasets. • Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. • Many others … 4/8/2019CS151SP19
  • 3. Pyplot • Pyplot is a collection of command style functions that make matplotlib work like MATLAB. Code Example: import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4]) plt.ylabel(“Numbers’) plt.show() 4/8/2019CS151SP19
  • 4. Plotting Functions Function Description pyplot.bar(x-value, y-value) pyplot.bar([x-values], [y-values]) Plots a single bar on the graph or multiple bars when the x- and y-values are provided as lists. pyplot.plot([x-coords], [y-coords]) pyplot.plot([x-coords], [y-coords], format) Plots a line graph. The color and style of the line can be specified with a format string. pyplot.grid("on") Adds a grid to the graph. pyplot.xlim(min, max) pyplot.ylim(min, max) Sets the range of x- or y-values shown on the graph. pyplot.title(text) Adds a title to the graph. pyplot.xlabel(text) pyplot.ylabel(text) Adds a label below the x-axis or to the left of the y-axis. pyplot.legend([label1, label2, ...]) Adds a legend for multiple lines. pyplot.xticks([x-coord1, x-coord2, ...], [label1, label2, ...]) Adds labels below the tick marks along the x-axis. pyplot.xticks([x-coord1, x-coord2, ...], [label1, label2, ...]) Adds labels to the left of the tick marks along the y-axis. pyplot.show() Displays the plot. 4/8/2019CS151SP19
  • 5. Creating a Line Graph • The following line allows us to call our plot plt instead of matplotlib.pyplot Import matplotlib.pyplot as plt # Set Plot Size (optional) plt.figure(figsize(20,10)) plt.style.use(‘ggplot’) 4/8/2019CS151SP19
  • 6. Example Cont. plt.plot(X,Y, color=‘red’, label=‘num’) _______________________ plt.plot(yearList, Avg_Tmax, label=‘Tmax’) plt.plot(yearList, Avg_Tmin, label=‘Tmin’) • plt is our plot • .plot() is a function that will plot a line chart. • X,Y is the data to be plotted, usually a list • Color is to manually control the color of the plotted line • Label will add the given string to the Legend if selected. 4/8/2019CS151SP19
  • 7. Example Cont. plt.plot(yearList, Avg_Tmax, label=‘Tmax’) plt.plot(yearList, Avg_Tmin, label=‘Tmin’) • yearList is my list of years, I called .keys() on my dictionary and it yields a list of years. • Avg_Tmax is my list of Tmax values from my averagedata.csv • Avg_Tmin is also from the Tmin from average data.csv. • Note we are not graphing standard deviation. 4/8/2019CS151SP19
  • 8. Example Cont. plt.plot(yearList, Avg_Tmax, label=‘Tmax’) plt.plot(yearList, Avg_Tmin, label=‘Tmin’) plt.plot(yearList, plotAvgMax, label=‘Max Avg’) Plt.plot(yearList, plotAvgMin, label=‘Min Avg’) • plotAvgMax is the average of all the years plotted on the graph. • It’s a single value, but the way graphing works. 4/8/2019CS151SP19
  • 9. List Comprehension • We need to get a single value in to a list that is of size N. • We could do a for loop plotAvgMax = [] for i in range(0, len(AVGDATA), 1): plotAvgMax = avgMax • Where plotAvgMax is given a copy of the avgMax in each element. • avgMax is the sum of all the yearly averages divided by the number of values. (typical arithmetic mean) 4/8/2019CS151SP19
  • 10. List Comprehension • We need to get a single value in to a list that is of size N. • The most pythonic way is to use a list comprehension: plotAvgMax = [avgMax for I in range(len(AVGDATA))] • This then gives us what we wanted. 4/8/2019CS151SP19
  • 11. Back to graphing # Set Title plt.title(‘Albuquerque, NM NOAA Values’) # Set Axis plt.xlabel(‘Year’) plt.ylabel(‘Temperature (F)’) # Add a legend plt.legend() # Save the file for your report plt.savefig(‘Homework2cplot.png’) # Show the plot plt.show() 4/8/2019CS151SP19
  • 12. Algorithm • Create Variables • Dictionary to hold Year: Tmax • Dictionary to hold Year: Tmin • Dictionary to hold Average data from averagedata.csv( year:[tmax, tmin] ) • List to hold all the Tmax values from homework2.csv • List to hold all the Tmin values from homeworlk2.csv 4/8/2019CS151SP19
  • 13. Algorithm • Load Data from homework2.csv into my two dictionaries • For every year • If the year has not changed: • Append Tmax to list • Append Tmin to list • Else the year has changed: • Update Year: Tmax list (deep copy) to a Dictionary (Max) • Update Year: Tmin list (deep copy) to a Dictionary (Min) • Max list clear • Min List clear • Set new year 4/8/2019CS151SP19
  • 14. Algorithm • Need to load data from averagedata.csv into dictionary. • For every row in averagedata: • Update in Dictionary Year: [Tmax, Tmin]  row[0]: [row[1], row[2]] • For graphing set a list of Avg_Tmax.append(float(row[1]) • For graphing set a list of Avg_Tmin.append(float(row[2]) • Sum Tmax values • Sum Tmin values • Create avgMax = sumTmax/len(Avg_Tmax) • Create avgMin = sumTmin/len(Avg_Tmin) 4/8/2019CS151SP19
  • 15. Algorithm • Now manual calc of Std Dev. • For every year in Tmax dictionary (from averagedata.csv) • For every item in Tmax list (from homework2.csv) • Max_sum += math.pow((item – average tmax value),2) • Max sigma = math.sqrt(max_sum / (length of Tmax list)) • Update a new dictionary with {row: max sigma} • Do the same for Tmin • You should now have two dictionaries, Tmax, Tmin with year: sigma 4/8/2019CS151SP19
  • 16. Algorithm • Calculate std deviation using statistics package • For every year in list of Tmax daily values • Max sigma.update( year: statistics.stdev(Tmax[day]) • Min sigma.update( year: statistics.stdev(Tmin[day} • Remember stddev takes a list, earlier in one of the for loops you should have created a list of every TMAX value and every TMIN value and create a TMAX dictionary with year: [list of tmax values] and TMIN dictionary with year: [list of tmin values] 4/8/2019CS151SP19
  • 17. Algorithm • Now create the graph. • plt.plot(yearList, Avg_Tmax, label='TMax') • plt.plot(yearList, Avg_Tmin, label='TMin') • plt.plot(yearList, plotAvgMax, label='Max Average') • plt.plot(yearList, plotAvgMin, label='Min Average’) • Here yearList is easy Tmax Dictionary.keys() • Avg_Tmax/Tmin were created when we read in the for loop for average data. • Use given list comprehension to generate plotAvgMax/Min 4/8/2019CS151SP19
  • 18. Algorithm • Write Report! • What is the data? • Format • What did you do to the data? Any formatting or cleaning? • A short description of your methodology: • I used a program to analyze the above data …. • Print the graph in the report • What is the graph telling you about 25 years of temperature data? • You have the standard deviation, can you tell me what that number means in terms of temperature year to year? • The temperatures are just numbers, what do they really mean in terms of subjective assessment to you! 4/8/2019CS151SP19
  • 19. Turn in • Homework2c.py file to learn. • Report in pdf format. • No longer than 1 page. 4/8/2019CS151SP19
  • 20. Final Project • You will receive a data file (csv format) of Sunspot data. • Utilizing what you have learned in Homework2 you will answer the following questions in a report: • Are there any discernable cycles for sunspots? • If yes, what is this cycle? • Can you prove it with a graph? • What are the statistics for each cycle? • Mean number per cycle • Std deviation per cycle 4/8/2019CS151SP19