Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Math 152: Intro to Mathematical Software
2017-03-03
Kiran Kedlaya; University of California, San Diego
adapted from lectures by William Stein, University of Washington
Lecture 22: Plotting: Matplotlib Pyplot vs Sage vs MATLAB
We follow http://matplotlib.org/users/pyplot_tutorial.html, and shows how to use the MATLAB-stype interface to matplotlib. We will cover topics:
plot: plotting a list of values
array of plots: axes and figures
1. Plot
MPL's plt.plot
is VERY different than Sage's plot!
plt.plot(x values, y yalues, options, [repeat])
In Sage, you use the line
command instead, and have to put the points together (using zip).
Also, in Sage, use frame=True
to draw a frame instead of -axes.
This is similar to MATLAB! -- see http://www.mathworks.com/help/matlab/ref/plot.html
Guess what this will do?
What will this do?
Exercise: Plot the polynomial using both matplotlib and Sage's plot commands, for .
2. Figures and Axes
Exercise: Copy the above code and instead make a 2x4 grid of plots (instead of a 2x2 grid). Just put whatever plots you want in.
In Sage, there is graphics_array (inspired by Mathematica...) to do the above grid layout.
Exercise: modify the above code to make a 2x2 array of plots using Sage plotting.