Skip to content

Exercises

This is the data that will be used in the following exercises.

import numpy as np
x = np.arange(0,100)
y = x*2
z = x**2

  1. Import matplotlib.pyplot as plt and set %matplotlib inline if you are using the jupyter notebook. What command do you use to show a plot if you aren't using the jupyter notebook?

  2. Follow along with these steps:

    1. Create a figure object called fig using plt.figure().
    2. Use add_axes to add an axis to the figure canvas at [0,0,1,1]. Call this new axis ax.
    3. Plot (x,y) on that axes and set the labels and titles to match the plot shown.
      Graph Graph
  3. Complete the following:

    1. Create a figure object and put two axes on it, ax1 and ax2. Located at [0,0,1,1] and [0.2,0.5,0.2,0.2] respectively.
      Graph Graph
    2. Now plot (x,y) on both axes. And call your figure object to show it.
      Graph Graph
  4. Complete the following:

    1. Create the plot below by adding two axes to a figure object at [0,0,1,1] and [0.2,0.5,0.4,0.4].
      Graph Graph
    2. Now use x,y, and z arrays to recreate the plot below. Notice the x limits and y limits on the inserted plot.
      Graph Graph
  5. Complete the following:

    1. Use plt.subplots(nrows=1, ncols=2) to create the plot below.
      Graph Graph
    2. Now plot (x,y) and (x,z) on the axes. Play around with the linewidth and style.
      Graph Graph
    3. See if you can resize the plot by adding the figsize() argument in plt.subplots() are copying and pasting your previous code.
      Graph Graph
  6. Plot (x,y) and (x,z) on the same axes and style with xkcd. Add text to match the following plot.
    Graph Graph