Introduction To Data Science
Introduction To Data Science
Standard Deviation
standard deviation 0.286
# add a title
plt.title("Nominal GDP")
Line graph.
• Good for showing trend.
• Type plt.plot? to see more options, such as
different marker and line styles, colors, etc.
import matplotlib.pyplot as plt
Acceptable
Bar charts
• Good for presenting/comparing numbers in discrete set of items
movies = ["Annie Hall", "Ben-Hur", "Casablanca", "Gandhi", "West Side Story"]
num_oscars = [5, 11, 3, 8, 10]
xs = range(len(movies)) # xs is range(5)
# plot bars with left x-coordinates [xs],
# heights [num_oscars]
plt.bar(xs, num_oscars)
# label x-axis with movie names at bar centers
plt.xticks(xs, movies)
# alternatively, use the following to replace
# the two lines above
#plt.bar(xs, num_oscars, tick_label=movies)
plt.scatter(friends, minutes)
plt.scatter(test_1_grades, test_2_grades)
plt.scatter(test_1_grades, test_2_grades)
plt.axis("equal")
Other important functions
• Create figures with numbers
• E.g. plt.figure(1), plt.figure(2), etc, to specify which figure to plot on
• Useful when dealing with multiple figures at the same time
• plt.xticks()
• plt.yticks()
• plt.savefig()
• Type in plt.savefig? for usage or search matplotlib documentation for
more details