Basic Matplotlib Exercises

See also: Matplotlib API

See also: Matplotlib.pyplot Documentation

See also: Matplotlib Examples



In [ ]:
# 1. Import matplotlib. Import matplotlib.pyplot as plt. Import numpy as np.

In [ ]:
# 2. Use the '%matplotlib inline' magic method. Run matplotlib.style.use('fivethirtyeight')

In [ ]:
# 3. Create a range of x values with np.arange(-10, 10, .5)

In [ ]:
# 4. Write a function that squares your x value. Make a list of y values that is the y = your_function(x).

In [ ]:
# 5. Use plt.plot() with your x and y values to make a line graph

In [ ]:
# 6. Use plt.scatter() with your x and y values to make a scatter graph.

In [ ]:
# 7. Use plt.subplots() and tuple unpacking to get your figure and axes. Assign to fig and ax.

In [ ]:
# 8. Get your axes by plt.gca() (get current axis). Get your figure by plt.gcf() (get current figure).

In [ ]:
# 9. Use your axes to change the x and y limits of the graph. Show the result.

In [ ]:
# 10. Replot your X and Y scatter graph.

In [ ]:
# 10. Use your axes to set the title of the graph, the x axis labels, and the y axis labels.

In [ ]:
# 11. Plot a second line on the graph of y=1.

In [ ]:
# 12. Save your graph using your figure's savefig() method to the data folder.