Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Welcome to Information Literacy IIGood morning!
• Lecture will start at 10:45 (let's wait for everyone).• If you have any question, please ask in the chat.• Note that lecture will be recorded.
• Please write your name there:https://forms.gle/YoUb9zT7Q2sX9WSD7
Lecture 2 – Chart with Matplotlib
Information Literacy II – EN(IL2) Course
Today's schedule
Review of last week
Overview of other toolsMicrosoft Excel
Google Sheets
Introduction to Python (cont'd)
Other type of graphs
Last week review (and more)
Saving chart to file
Use plt.savefig(filename)
File type is decided by extension:figure.pdf or figure.png or figure.jpg or …
Mini-exercise:Save the same plot using .pdf and .pngDo you see any difference?What are the advantages/drawbacks of these formats?
Comparing .pdf or .png
Both are portable: readable on (almost) all computersPdf files can contain vector graphicsPng files contain only raster graphics
Possible to zoom with pdf files, but potentially larger files for complex plot (e.g. with many points)Both formats can be used in LaTeX
Other tools (no slides – only demo)
Introduction to Python
Python (again)List ComprehensionsCreate new lists easilyCan be used to modify data
Simple examplesnumbers = [1, 2, 3, 4, 5, 6, 7]squared = [x**2 for x in numbers]total = sum(numbers)percentage = [x/total*100 for x in numbers]
Mini-exercise:Given a list of numbers, create- a list containing the last digit of each elements- a list containing the first digit of each elements
Remark: the second question is HARD; please try but I do not expect you to be able to do it without help.
# InputL = [104, 71, 234, 78, 9, 23]
# Outputlast = [4, 1, 4, 8, 9, 3]first = [1, 7, 2, 7, 9, 2]
Other type of charts
Charts typeMany types of charts:Line Chart
Bar Chart
Histogram
Pie Chart
Gantt Chart
Need to know when/how to use each of them
All images from Wikipedia.
foreignBStudents = [173, 172, 194, 248, 276,294, 307, 282, 267, 252,238, 220, 187, 170, 174,186, 210, 239, 249, 267]
years = list(range(2000, 2020))
# Axis labels and graph titleplt.xlabel("Academic year")plt.ylabel("Number of students")plt.title("Number of undegraduate foreign students in Titech")
# Small modifications of axisplt.xticks([2000, 2005, 2010, 2015, 2019])plt.ylim(0, 320)
# Only this line change compared to before!plt.bar(years, foreignBStudents)
# Save the generated graph to fileplt.savefig("BStudentsTokyTech.png")
Bar Chart
Pie ChartExercise (difficult):
- Google “statistics tokyo tech” or find on Tokyo Tech website
- Look for information on how to draw pie charts
- Draw a graph similar to the one on the right
(It may be difficult to display the percentage values)
plt.pie() creates the pie chart
It takes the sizes of each slice and the labels
Find how to add the percentage values by yourself
Look for examples online. Impossible to guess.
Use plt.axis(‘equal’) to have a circular pie
Try without this line and see the result
names = ['Science', 'Engineering', 'Materials', 'Computing', 'Life', 'Environment']sizes = [151, 358, 183, 92, 150, 134]
plt.pie(sizes, labels=names)plt.axis('equal')
plt.title('Admission quota (AY2016)')plt.savefig("quota.png")
Pie Chart