ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 07 Jul 2012 16:12:54 -0500Matplotlib cannot create a graphhttps://ask.sagemath.org/question/9105/matplotlib-cannot-create-a-graph/Hello! Using www.sagenb.com I typed the following code in the cell of my worksheet:
import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.show()
Unfortunately there isn't any graph under the cell. What should I do? Thanks.Sat, 07 Jul 2012 03:59:10 -0500https://ask.sagemath.org/question/9105/matplotlib-cannot-create-a-graph/Answer by calc314 for <p>Hello! Using <a href="http://www.sagenb.com">www.sagenb.com</a> I typed the following code in the cell of my worksheet:</p>
<pre><code>import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.show()
</code></pre>
<p>Unfortunately there isn't any graph under the cell. What should I do? Thanks.</p>
https://ask.sagemath.org/question/9105/matplotlib-cannot-create-a-graph/?answer=13806#post-id-13806You just need to modify your last line.
import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.savefig('test.png')
You might want to include x-coordinates to the get plot you want.
import matplotlib.pyplot as plt
plt.plot([1,2,3,4],[1, 3, 2, 4])
plt.savefig('test.png')
Also, you can get a nice plot in Sage with `list_plot` that might do the job for you.
Sat, 07 Jul 2012 05:48:26 -0500https://ask.sagemath.org/question/9105/matplotlib-cannot-create-a-graph/?answer=13806#post-id-13806Comment by kcrisman for <p>You just need to modify your last line.</p>
<pre><code>import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.savefig('test.png')
</code></pre>
<p>You might want to include x-coordinates to the get plot you want.</p>
<pre><code>import matplotlib.pyplot as plt
plt.plot([1,2,3,4],[1, 3, 2, 4])
plt.savefig('test.png')
</code></pre>
<p>Also, you can get a nice plot in Sage with <code>list_plot</code> that might do the job for you.</p>
https://ask.sagemath.org/question/9105/matplotlib-cannot-create-a-graph/?comment=19430#post-id-19430`points(...)` or `line(...,linestyle='')` are also good ideas.Sat, 07 Jul 2012 16:12:54 -0500https://ask.sagemath.org/question/9105/matplotlib-cannot-create-a-graph/?comment=19430#post-id-19430Comment by AndreWin for <p>You just need to modify your last line.</p>
<pre><code>import matplotlib.pyplot as plt
plt.plot([1, 3, 2, 4])
plt.savefig('test.png')
</code></pre>
<p>You might want to include x-coordinates to the get plot you want.</p>
<pre><code>import matplotlib.pyplot as plt
plt.plot([1,2,3,4],[1, 3, 2, 4])
plt.savefig('test.png')
</code></pre>
<p>Also, you can get a nice plot in Sage with <code>list_plot</code> that might do the job for you.</p>
https://ask.sagemath.org/question/9105/matplotlib-cannot-create-a-graph/?comment=19436#post-id-19436Thank you very much for you answer!Sat, 07 Jul 2012 06:50:51 -0500https://ask.sagemath.org/question/9105/matplotlib-cannot-create-a-graph/?comment=19436#post-id-19436