 CoCalc Public FilesDaniel's materials / lab_videos / lab3.ipynb
Author: Daniel Sun
Views : 17
Description: Tutorial for Lab 3, LS30A (Fall 2020)
Compute Environment: Ubuntu 20.04 (Default)

# Lab 3 Using Lists and Loops

Example 1: Plotting lists of points using list_plot()

In :
# height over time

height=[61, 62, 66, 68, 70]
ages = [10, 12, 14, 16, 17]

list_plot(height) In :
# plot list of pairs of points

pairs = [(10, 61), (12, 62), (14, 66), (16, 68), (17, 70)]
list_plot(pairs, size=50, color='green', axes_labels=["ages [yr]", "height [in]"], title="My height over time") In :
pairs = list(zip(ages, height)) # replacement for typing the above.
list_plot(pairs, size=50, color='green', axes_labels=["ages [yr]", "height [in]"], title="My height over time") In :
# Convert inches to m

height

# create an empty list to hold the metric heights
metric_heights = []

# repeatedly, for each item in the list height...
for h in height:
# convert height to meters
h_meters = h*0.0254

# append converted height to metric list
metric_heights.append(h_meters)

# display converted time series.
list_plot(list(zip(ages, metric_heights)), size=50, color='green', axes_labels=["ages [yr]", "height [m]"], title="My height over time") Example 3: editing a trajectory

xlist = [1, 0.995004165278026, 0.980066577841242, 0.955336489125606, 0.921060994002885]... ylist = [0, 0.0998334166468282, 0.198669330795061, 0.295520206661340, 0.389418342308651]...
In :
old_circle = list_plot(list(zip(xlist, ylist)), aspect_ratio=1)
show(old_circle) In :
new_cos_list = []
for x in xlist:
new_cos_list.append(2*x)
new_cos_list

new_sin_list = []
for y in ylist:
new_sin_list.append(2*y)
new_sin_list

new_circle = list_plot(list(zip(new_cos_list, new_sin_list)), aspect_ratio=1, color='red', plotjoined=True)

# overlay both:
new_circle + old_circle In [ ]: