Welcome to Information Literacy II Good 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:
Welcome to Information Literacy II Good morning! Lecture will start - - PowerPoint PPT Presentation
Welcome to Information Literacy II Good 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:
Review of last week Overview of other tools
Microsoft Excel Google Sheets
Introduction to Python (cont'd) Other type of graphs
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 .png Do you see any difference? What are the advantages/drawbacks of these formats?
Both are portable: readable on (almost) all computers Pdf files can contain vector graphics Png 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
List Comprehensions Create new lists easily Can be used to modify data Simple examples numbers = [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
Remark: the second question is HARD; please try but I do not expect you to be able to do it without help.
# Input L = [104, 71, 234, 78, 9, 23] # Output last = [4, 1, 4, 8, 9, 3] first = [1, 7, 2, 7, 9, 2]
Many 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 title plt.xlabel("Academic year") plt.ylabel("Number of students") plt.title("Number of undegraduate foreign students in Titech") # Small modifications of axis plt.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 file plt.savefig("BStudentsTokyTech.png")
Exercise (difficult):
pie charts
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', 'Ma terials', 'Computing', 'Life', 'Enviro nment'] sizes = [151, 358, 183, 92, 150, 134] plt.pie(sizes, labels=names) plt.axis('equal') plt.title('Admission quota (AY2016)') plt.savefig("quota.png")