ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 11 Sep 2018 15:14:09 +0200Only one of two identical entries in the notebook gives graphics output for show()https://ask.sagemath.org/question/43638/only-one-of-two-identical-entries-in-the-notebook-gives-graphics-output-for-show/I use SageMath to teach a bunch of kids. I have to confess a certain amount of frustration with the SageMath notebook. In particular, tonight I composed a notebook entry which shows some data points and curve-fitted plots. I pressed Shift-Enter to evaluate, and there was no graphical output (nor any error message).
And then I copied/pasted the exact same entry into a blank entry in the same SageMath notebook, pressed Shift-Enter, and it showed the graphical output.
Yes, this is the SAME notebook page which, if you scroll up, shows no graphical output (I inserted a print("Ok.") just to confirm that there was SOME output), and if you scroll down, you see the IDENTICAL python-like SageMath script, and then it shows the graphics of the plotted points as desired.
How could this happen? Is there something that happens in between notebook entries? Perhaps only the last entry is evaluated? I will try posting screenshots.
ok, the screen shots are as follows:
<a href="https://pasteboard.co/HDowwUc.png">no plot, just text</a>
<a href="https://pasteboard.co/HDoxbZ1.png">plot after the text</a>
in the first entry, you can see the notebook entry, and then underneath in blue the SageMath output "Ok.", and that's all; the next notebook entry follows immediately. There is no plot.
in the second entry, you can see the notebook entry, and then underneath in blue the SageMath output "Ok.", and under that is the plot of the two data points and the axes.
For what it's worth, the SageMath notebook entry is as follows. The variable "stage" is so that I can easily turn on/off various parts of the entry by modifying it as I get to various parts of the lesson. (But there is no difference between the entry that works and the entry that doesn't.)
"all_go" is the accumulation of all the graphics objects that I want to display, that is, the output of the points() function in this case, and depending on the setting of my "stage" variable, possibly also a plot of f(x).
I am using SageMath 7.5.1 on Kubuntu 14.04. I know it's not the newest version, but I mst be missing something.
Any help would be appreciated
<pre>
---( start )---
stage="p2m1"
# stage can be p2 or p3 = data points
# stage can be d0 or d1 = display
# stage can be m1 or m2 or me = model
var('a,b,c')
if stage.find("p2") >= 0 :
mydata = [[1,2],[3,5]]
else :
mydata = [[1,2],[2,4],[3,5]]
#mydata
mydata_plot = points(mydata,color='purple', size=100)
if stage.find("m1") >= 0 :
mymodel(x) = b*x + c
elif stage.find("m2") >= 0 :
mymodel(x) = a*x^2 + b*x + c
elif stage.find("me") >= 0 :
mymodel(x) = a*exp(b*x) + c
myfit = find_fit(mydata,mymodel,solution_dict=True)
if stage.find("m1") >= 0 :
f(x) = mymodel(b=myfit[b], c=myfit[c])
else :
f(x) = mymodel(a=myfit[a], b=myfit[b], c=myfit[c])
#f(x) = 6 - 2^(3-x)
#f(x) = (-8) * exp( x*(-ln(2))) + 6
mymodel_plot = plot( f, (x,0,4,), color='red')
all_go = mydata_plot
if stage.find("d1") >= 0 :
all_go += mymodel_plot
t_min=0
t_max=5
t_default=1.5
sample_t=t_default
global_go = all_go
all_go
if stage.find("d1") < 0 :
all_go.show()
print("Ok.")
elif stage.find("d1") >= 0 :
@interact
def _(sample_t=slider(t_min, t_max, default=t_default, step_size=0.1)):
global global_go
all_go = global_go
#sample_t=2
output_y = f(sample_t)
point_tuple = ( sample_t, output_y )
plotpoint_go = point2d( point_tuple , size=200, color='green')
all_go += plotpoint_go
all_go.show()
f.show()
print( "f(" + str(sample_t) + ") = " + str(output_y) )
---( end )---
</pre>
quantumTue, 11 Sep 2018 15:14:09 +0200https://ask.sagemath.org/question/43638/What to do to save a plot from notebook?https://ask.sagemath.org/question/39624/what-to-do-to-save-a-plot-from-notebook/Is it possible to export a plot, preferable in a vector format from a notebook?boosterFri, 17 Nov 2017 09:24:37 +0100https://ask.sagemath.org/question/39624/show several graphics in notebookhttps://ask.sagemath.org/question/9990/show-several-graphics-in-notebook/I want to show several plots in the notebook, one after the other. If I have only one plot, I can usually show it with the function sum(), but if I put something else after the sum() then the plot doesn't show. So, for example, I want to show several plots one after the other by doing a while with the sum inside, but that doesn't work. It doesn't show any plot.barefegThu, 04 Apr 2013 19:12:59 +0200https://ask.sagemath.org/question/9990/No result in published worksheethttps://ask.sagemath.org/question/9890/no-result-in-published-worksheet/Hey guys..
I just can't find out what's the problem. When I am editing my worksheet everything works for this example from the wiki:
srg = srange(-4,4,1/10,include_endpoint=True)
@interact
def dualv(a1=slider(srg,default=1),a2=slider(srg,default=2), a3=slider(srg,default=-1),a4=slider(srg,default=3)):
A1 = arrow2d([0,0],[a1,a2],rgbcolor='black')
A2 = arrow2d([0,0],[a3,a4],rgbcolor='black')
A3 = arrow2d([0,0],[a1,a3],rgbcolor='black')
A4 = arrow2d([0,0],[a2,a4],rgbcolor='black')
p1 = polygon([[0,0],[a1,a2],[a1+a3,a2+a4],[a3,a4],[0,0]], alpha=.5)
p2 = polygon([[0,0],[a1,a3],[a1+a2,a3+a4],[a2,a4],[0,0]],rgbcolor='red', alpha=.5)
A = matrix([[a1,a2],[a3,a4]])
html('<h3>The determinant of a matrix is equal to the determinant of the transpose</h3>')
html("$det(%s) = det(%s)$"%(latex(A),latex(A.transpose())))
show(A1+A2+A3+A4+p1+p2)
But when I publish this worksheet, the plot is not evaluated/shown/rendered. The control-bars are here but not the graphics. I've checked the HTML-contend.. there is none.
<table border="0" width="100%" bgcolor="white">
<tbody>
<tr>
<td valign="top" bgcolor="white" align="left">
<pre></pre>
</td>
</tr>
<tr>
<td valign="top" align="left"></td>
</tr>
</tbody>
</table>
Does anyone know what's the problem here? And could anyone tell me how I can see a log of what the server got from the client and of what the server did in response?
Thank you for any help.
snoocThu, 07 Mar 2013 12:09:04 +0100https://ask.sagemath.org/question/9890/no more inline matplotlib plots in sage notebookhttps://ask.sagemath.org/question/8608/no-more-inline-matplotlib-plots-in-sage-notebook/Hi,
I can't get any matplotplib/pylab plots inline in a notebook. Plots now are created as pdf files that open in another window.
For example, the code below used to create the plot in a new box after the instruction plt.savefig('.')
import numpy as np
import pylab as plt
x = np.arange(-2 * np.pi, 2 * np.pi,0.1)
plt.figure(1)
plt.clf()
plt.plot(x, np.sin(x), label='sin(x)')
plt.savefig('.')
now it returns a link '.pdf' to a pdf file.
Using
plt.savefig('a.png')
returns the following traceback:
Traceback (most recent call last):
File "", line 1, in <module>
File "/private/var/folders/k7/k7XHz3-82RazCk+kNOj55U+++TM/-Tmp-/tmpjD4zHK/___code___.py", line 14, in <module>
exec compile(u"plt.savefig('a.png')" + '\n', '', 'single')
File "", line 1, in <module>
File "/tmp/sage-mac-app/local/lib/python2.6/site-packages/matplotlib/pyplot.py", line 363, in savefig
return fig.savefig(*args, **kwargs)
File "/tmp/sage-mac-app/local/lib/python2.6/site-packages/matplotlib/figure.py", line 1084, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/tmp/sage-mac-app/local/lib/python2.6/site-packages/matplotlib/backend_bases.py", line 1853, in print_figure
print_method = self._get_print_method(format)
File "/tmp/sage-mac-app/local/lib/python2.6/site-packages/matplotlib/backend_bases.py", line 1793, in _get_print_method
'%s.' % (format, ', '.join(formats)))
ValueError: Format "png" is not supported.
Supported formats: pdf.
I don't know what settings changes I may have done, and couldn't find any documented help format settings in sage for matplotlib plots. Interestingly I used to experience before the impossibility to export sage generated plots in pdf... It would be nice to have a better control on these settings.
Thank you for any help
Samuel
sbottThu, 05 Jan 2012 05:23:41 +0100https://ask.sagemath.org/question/8608/Plot display problems when changing IP address?https://ask.sagemath.org/question/8464/plot-display-problems-when-changing-ip-address/The following senario has happened to me a couple of times when using Sage to demonstrate things in a classroom.
1. I'm working on a worksheet containing plots of simple functions for a calculus class in my office. The worksheet is on a notebook server somewhere (on campus, at sagenb.org, etc..).
2. I close my laptop, walk downstairs to class, open my laptop and plug into the projector. The laptop is now on a different wireless network, but still connects to the sage notebook server just fine. I get a red "searching for sage server" notice for just a second and then it disappears and the worksheet behaves like normal.
3. I'm half way through class, showing plots of this and that, and I decide that I want to change the bounds on one of my plots.
Say I have
f(x) = 3*x^4+4*x^3-6*x^2
plot( f, (x,-2,3) )
and I want to zoom in and look at
plot( f, (x, -1, 1) )
and a new plot shows up, but it's not quite right. Sometimes I've had the experience that the plot doesn't change at all, I get the same plot as before (i.e. after editing the cell and hitting shift+enter again). Sometimes I get a new plot, but it's not correct. For example, this happened today and I got a new plot which was on the interval (-2, 1) not (-1, 1). I keep editing the cell and trying to re-evaluate the plot and get just continue to get incorrect domains or unchanged plots.
It seems like something is going on with cached images, or old images being re-displayed.
I finally figured out that I can solve the problem by cutting and pasting the code into a new cell, changing the name of the function to something different like h(x), and evaluating the cell.
Any thoughts on why this is happening or how I can prevent it from happening in the middle of class? Do I need to completely log out / log in to the server every time my IP address changes? Or maybe this problem is completely unrelated to the network change.benjaminfjonesThu, 10 Nov 2011 18:21:22 +0100https://ask.sagemath.org/question/8464/Plotting x, free variable errorhttps://ask.sagemath.org/question/7760/plotting-x-free-variable-error/I was plotting sin(x)/x and also wanted a seperate plot of sin(x) and x so I could visualize those components as well. However I get an error when plotting x saying "free variable x -> x". If I add a coefficient to h(x) such as `h(x) = 1.0001*x` then it works fine.
This is the code I am using:
f(x) = sin(x)/x
g(x) = sin(x)
h(x) = x
fig1 = plot(f,-10,10,rgbcolor='green')
fig2 = plot(g,-10,10,rgbcolor='purple')
fig3 = plot(h,-10,10,rgbcolor='red')
figure = fig1 + fig2 + fig3
show(figure,xmin=-10,xmax=10,ymin=-10,ymax=10,figsize=[8,8],fontsize=20)AaronLSTue, 09 Nov 2010 21:50:44 +0100https://ask.sagemath.org/question/7760/