Open nicksmithc102 opened 8 years ago
@cswiercz is planning on going over this assignment tomorrow in class, he may cover this topic.
Create a cell with the following code:
# In [xyz]:
%matplotlib inline
import matplotlib.pyplot as plt
within that cell you can now plot things using the usual plotting commands described in the primary reference on Matplotlib. For example,
# In [xyz]:
%matplotlib inline
import matplotlib.pyplot as plt
x = [1,2,3]
y = [-1,1,0]
plt.plot(x, y, 'bo-')
plt.show()
Below the cell an image should appear as a .png
file. There are additional saving options if you look at the documentation to plt.savefig()
.
(The %matplotlib inline
bit is a notebook-specific command to tell matplotlib to display the plots in the notebook as opposed to doing...well...something else.)
Somewhat related: In today's (April 12th) lecture I went over how to import the code written in homework1-githubusername/homework1/exercise1.py
into a notebook located in homework1-githubusername/
.
I just tried plotting on Sage and got kicked out of ipython altogether. The message was: "QXcbConnection: Could not connect to display Aborted (core dumped)" I feel like there could be lots of different possible explanations here, including hardware insufficiencies on my end. But ... any ideas!?
Usually you get this error if you do not have a "display" for the plot. Are you using Jupyter notebook to plot? If yes, could you post your ipynb (via opening an issue on your private homework1 repository)?
Also refer to this Issue 1
I will attempt to later today!
Thanks, Meghana.
Actually, it's working in the Jupyter notebooks now.... I think maybe before I was trying it in the terminal, though I guess I don't understand what the relevant difference is here.
I suppose the thing to do at the end would be simply to download the notebook as a .pdf file? Is it okay if there are multiple .pdfs in my "report" folder? (Alternatively, I suppose I could merge all the files if need be....)
Thanks again.
Glad it works for you now.
You could, potentially, write up your report using the notebook. In fact, this might be a good thing to demo for the class. I'll briefly do this on Tuesday.
How does one plot something in Sagemath? Using matplotlib, specifically?