In [ ]:
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
In [ ]:
a = np.array([0.39, 0.72, 1.00, 1.52, 5.20, 9.54, 19.22, 30.06, 39.48])
These are in units where the Earth-Sun distance is 1 (astronomical units).
The corresponding periods of their orbits (how long they take to go once around the Sun) are, in years
In [ ]:
P = np.array([0.24, 0.62, 1.00, 1.88, 11.86, 29.46, 84.01, 164.8, 248.09])
Finally, the names of the planets corresponding to these are:
In [ ]:
names = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn",
"Uranus", "Neptune", "Pluto"]
(technically, pluto isn't a planet anymore, but we still love it :)
Plot as points, the periods vs. distances for each planet on a log-log plot.
Write the name of the planet next to the point for that planet on the plot
In [ ]:
For an angle $\theta$ in the range $\theta \in [0, 2\pi]$, the polar equations of a circle of radius $R$ are: $$ x = R\cos(\theta) $$ $$ y = R\sin(\theta) $$
We want to draw a circle.
x and y arrays from theta for your choice of $R$y vs. xNow, look up the matplotlib fill() function, and draw a circle filled in with a solid color.
In [ ]:
Generalize your circle drawing commands to produce a function,
draw_circle(x0, y0, R, color)
that draws the circle. Here, (x0, y0) is the center of the circle, R is the radius, and color is the color of the circle.
Now randomly draw 10 circles at different locations, with random radii, and random colors on the same plot.
In [ ]:
Download the data file of global surface air temperature averages from here: https://raw.githubusercontent.com/sbu-python-summer/python-tutorial/master/day-4/nasa-giss.txt
(this data comes from: https://data.giss.nasa.gov/gistemp/graphs/)
There are 3 columns here: the year, the temperature change, and a smoothed representation of the temperature change.
np.loadtxt(). You might find the NumPy where() function useful.
In [ ]:
matplotlib has a number of ways to create multiple axes in a figure -- look at plt.subplot() (http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.subplot)
Create an x array using NumPy with a number of points, spanning from $[0, 2\pi]$.
Create 3 axes vertically, and do the following:
f initialized to a function of your choice.f,
$$ f' = \frac{f_{i+1} - f_i}{\Delta x}$$
and plot this in the middle axes
In [ ]:
In this exercise, we will read the file with the transcription of Star Trek TOS, Shore Leave and calculate the amount of time each word was found. We will then plot the 25 most frequent words and label the plot.
shore_leave.txtcount shows the amount of times the word was found in the text. Remember to get rid of the punctuation ("." and ",") and to ensure that all words are lowercase
In [ ]:
f = open("shore_leave.txt", "r")
for line in f:
pass
In [1]:
# your code here
In [ ]: