This assignment helps you review the fundamental operations of Matplotlib (covered by our labs) and self-learn some new features (not covered by our labs). Please store all your solutions in a single Python file. Use a separate cell for each question.
- Write a Python program that generates the following figure with 4 subplots, each with a differentmarker style.
Hint: when you call the scatter() function, set the marker parameter to +, x, 4, and 5 respectively, for the four different marker style. E.g., axes.scatter(x, y, marker=+).
Marker reference: https://matplotlib.org/api/markers_api.html#module-matplotlib.markers
- Assume a dictionary books = {Tom:10, Dick:11, Harry:9, Slim:7, Jim:12} stores the number of books of five students. Write a Python program that generates the following figure.
Hint:
- to get the list of dictionary values, you can use list(books.values());
- to get the list of dictionary keys (as the y-axis labels), you can use list(books);
- to set the y-axis ticks and labels, use function set_yticks() and set_yticklabels(). You can learn from the following online example to set the y-axis labels correctly:
https://matplotlib.org/gallery/lines_bars_and_markers/barh.html
- Study the example at https://matplotlib.org/gallery/lines_bars_and_markers/simple_plot.html. Then write a Python program that generates the following figure with 2 subplots.
Hint: you may need to use the tight_layout() function to set a tight layout.
Reviews
There are no reviews yet.