Skip to content

Latest commit

 

History

History
62 lines (46 loc) · 2.24 KB

File metadata and controls

62 lines (46 loc) · 2.24 KB

Matplotlib Problem Set

Bar Chart

Use the following data to make your plot:

import numpy as np
x = np.arange(1, 13)
y = np.array([7, 8, 5, 5, 3, 4, 4, 6, 9, 7, 8, 8])
  1. Add a bar chart to your plot, using x and y above. Fix it so there is no outline (edgecolor), set the color of the bars to green, and set their width to 0.25.
  2. Fix your X-axis to go from 1 to 13.
  3. Fix your Y-axis to go from 0 to 10.
  4. Add a label to your X-axis that says "month of the year".
  5. Add a label to your Y-axis that says "letters in month name".
  6. Add a title to your plot, "Leters in the Name of Each Month".
  7. Display your plot.

Scatter and Line Plots

Use the following data:

import numpy as np
x = np.arange(0.0, 2 * np.pi, np.pi / 16.0)
y = 2 * np.cos(x)
  1. Add a line plot, using x and y above. Set the width of the line to 3, set the color to green, set the style to dashed, with a label of "approx".
  2. Add a scatter plot, using x and y above. Set the size to 1000, set the edgecolor to none, set the color to blue, and set the label to "discrete".
  3. Add an X label of "x".
  4. Add a Y label of "Y".
  5. Add a title of "2 * cos(x)".
  6. Save your plot to a file named "cos.png".

Multiplot, Histogram, and Errorbar

Use the following data:

import numpy as np
mu = 10500
sigma = 250
values = mu + sigma * np.random.randn(10000)
x = mu + sigma * np.random.randn(100)
y = mu + sigma * np.random.randn(100)
  1. Use subplot to initialize the first plot (left column) in a two-column subplot image.
  2. Create a histogram of values with 25 columns, set the facecolor to green, and set the edgecolor to none.
  3. Give the plot a Y-label of "count" of values".
  4. Use subplot to intiialize the second plot (right column) in a two-column subplot image.
  5. Create a scatter plot of x and y, set the area to 300, set alpha to 0.25, set edgecolor to none, set color equal to random.rand(100).
  6. Give the plot a X-label of "x".
  7. Give the plot a Y-label of "y".
  8. Set the x-limits of the plot to: 10,000 to 11,000.
  9. Set the y-limits of the plot to: 10,000 to 11,000.
  10. Add a grid to the plot.
  11. Show the plot.

Solutions

Back to Lecture