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.Thu, 02 Jun 2016 01:01:28 +0200show() does not show in the right placehttps://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/ Why the show() funtion does not show in the right position?
It should show between the BEFORE and AFTER prints, but actually if you run the code, it will appear right before the first print (see the code): print ("BEFORE SHOW ", i)
print ("Create a graph")
G = Graph(sparse=True)
G.allow_multiple_edges(True)
G.add_edge(1,2,"blue")
G.add_edge(2,3,"green")
G.add_edge(3,1,"red")
G.add_edge(1,4,"green")
G.add_edge(2,4,"red")
G.add_edge(3,4,"blue")
for i in range(5):
print ("BEFORE SHOW ", i)
show(G)
print ("AFTER SHOW ", i)
print ("BEFORE PLOT ", i)
G.plot()
print ("AFTER PLOT ", i)Tue, 31 May 2016 10:36:00 +0200https://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/Comment by B r u n o for <p>Why the show() funtion does not show in the right position?</p>
<p>It should show between the BEFORE and AFTER prints, but actually if you run the code, it will appear right before the first print (see the code): print ("BEFORE SHOW ", i)</p>
<pre><code>print ("Create a graph")
G = Graph(sparse=True)
G.allow_multiple_edges(True)
G.add_edge(1,2,"blue")
G.add_edge(2,3,"green")
G.add_edge(3,1,"red")
G.add_edge(1,4,"green")
G.add_edge(2,4,"red")
G.add_edge(3,4,"blue")
for i in range(5):
print ("BEFORE SHOW ", i)
show(G)
print ("AFTER SHOW ", i)
print ("BEFORE PLOT ", i)
G.plot()
print ("AFTER PLOT ", i)
</code></pre>
https://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/?comment=33594#post-id-33594What do you mean by "not in the right position"? (Your question is very unclear to me!)Tue, 31 May 2016 11:17:01 +0200https://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/?comment=33594#post-id-33594Comment by stefanutti for <p>Why the show() funtion does not show in the right position?</p>
<p>It should show between the BEFORE and AFTER prints, but actually if you run the code, it will appear right before the first print (see the code): print ("BEFORE SHOW ", i)</p>
<pre><code>print ("Create a graph")
G = Graph(sparse=True)
G.allow_multiple_edges(True)
G.add_edge(1,2,"blue")
G.add_edge(2,3,"green")
G.add_edge(3,1,"red")
G.add_edge(1,4,"green")
G.add_edge(2,4,"red")
G.add_edge(3,4,"blue")
for i in range(5):
print ("BEFORE SHOW ", i)
show(G)
print ("AFTER SHOW ", i)
print ("BEFORE PLOT ", i)
G.plot()
print ("AFTER PLOT ", i)
</code></pre>
https://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/?comment=33595#post-id-33595It should show between the BEFORE and AFTER prints, but actually if you run the code, it will appear right before the first print: print ("BEFORE SHOW ", i)Tue, 31 May 2016 11:27:19 +0200https://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/?comment=33595#post-id-33595Comment by kcrisman for <p>Why the show() funtion does not show in the right position?</p>
<p>It should show between the BEFORE and AFTER prints, but actually if you run the code, it will appear right before the first print (see the code): print ("BEFORE SHOW ", i)</p>
<pre><code>print ("Create a graph")
G = Graph(sparse=True)
G.allow_multiple_edges(True)
G.add_edge(1,2,"blue")
G.add_edge(2,3,"green")
G.add_edge(3,1,"red")
G.add_edge(1,4,"green")
G.add_edge(2,4,"red")
G.add_edge(3,4,"blue")
for i in range(5):
print ("BEFORE SHOW ", i)
show(G)
print ("AFTER SHOW ", i)
print ("BEFORE PLOT ", i)
G.plot()
print ("AFTER PLOT ", i)
</code></pre>
https://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/?comment=33596#post-id-33596`show()` isn't necessarily designed to "show" in a particular spot. It is designed to give a graphical representation of whatever you have (not necessarily a plot), but no guarantees to placement, because it was designed for command-line usage originally. Which GUI are you using here - the Sage cell, sagenb, or Sage Math Cloud? It would likely depend on this.Tue, 31 May 2016 17:51:19 +0200https://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/?comment=33596#post-id-33596Comment by stefanutti for <p>Why the show() funtion does not show in the right position?</p>
<p>It should show between the BEFORE and AFTER prints, but actually if you run the code, it will appear right before the first print (see the code): print ("BEFORE SHOW ", i)</p>
<pre><code>print ("Create a graph")
G = Graph(sparse=True)
G.allow_multiple_edges(True)
G.add_edge(1,2,"blue")
G.add_edge(2,3,"green")
G.add_edge(3,1,"red")
G.add_edge(1,4,"green")
G.add_edge(2,4,"red")
G.add_edge(3,4,"blue")
for i in range(5):
print ("BEFORE SHOW ", i)
show(G)
print ("AFTER SHOW ", i)
print ("BEFORE PLOT ", i)
G.plot()
print ("AFTER PLOT ", i)
</code></pre>
https://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/?comment=33599#post-id-33599I'm using the cloud sagemath worksheet. sagewsTue, 31 May 2016 18:29:53 +0200https://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/?comment=33599#post-id-33599Comment by JEFLSU for <p>Why the show() funtion does not show in the right position?</p>
<p>It should show between the BEFORE and AFTER prints, but actually if you run the code, it will appear right before the first print (see the code): print ("BEFORE SHOW ", i)</p>
<pre><code>print ("Create a graph")
G = Graph(sparse=True)
G.allow_multiple_edges(True)
G.add_edge(1,2,"blue")
G.add_edge(2,3,"green")
G.add_edge(3,1,"red")
G.add_edge(1,4,"green")
G.add_edge(2,4,"red")
G.add_edge(3,4,"blue")
for i in range(5):
print ("BEFORE SHOW ", i)
show(G)
print ("AFTER SHOW ", i)
print ("BEFORE PLOT ", i)
G.plot()
print ("AFTER PLOT ", i)
</code></pre>
https://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/?comment=33600#post-id-33600I think the original post is questioning the order in which the outputs are displayed in the output of the SMC cell. If my input is something like:
print 1
print 2
I would expect the 1 to be displayed before the 2; in this case, you expect ("BEFORE SHOW ",0) to be the first line of output, followed by the image of the graph, yes? But that's not what it is doing. The topmost output is the graph, then ("BEFORE SHOW ",0), etc.
Is that the question?Tue, 31 May 2016 20:25:31 +0200https://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/?comment=33600#post-id-33600Answer by William Stein for <p>Why the show() funtion does not show in the right position?</p>
<p>It should show between the BEFORE and AFTER prints, but actually if you run the code, it will appear right before the first print (see the code): print ("BEFORE SHOW ", i)</p>
<pre><code>print ("Create a graph")
G = Graph(sparse=True)
G.allow_multiple_edges(True)
G.add_edge(1,2,"blue")
G.add_edge(2,3,"green")
G.add_edge(3,1,"red")
G.add_edge(1,4,"green")
G.add_edge(2,4,"red")
G.add_edge(3,4,"blue")
for i in range(5):
print ("BEFORE SHOW ", i)
show(G)
print ("AFTER SHOW ", i)
print ("BEFORE PLOT ", i)
G.plot()
print ("AFTER PLOT ", i)
</code></pre>
https://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/?answer=33601#post-id-33601The problem is Python output buffering. Put `sys.stdout.flush()` after each print statement to ensure that the output is flushed to the output stream **immediately**, so you can see it then. The show command always flushes immediately, which is why it appears before.Tue, 31 May 2016 20:52:47 +0200https://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/?answer=33601#post-id-33601Comment by stefanutti for <p>The problem is Python output buffering. Put <code>sys.stdout.flush()</code> after each print statement to ensure that the output is flushed to the output stream <strong>immediately</strong>, so you can see it then. The show command always flushes immediately, which is why it appears before.</p>
https://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/?comment=33604#post-id-33604It did work! Thanks youWed, 01 Jun 2016 00:19:19 +0200https://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/?comment=33604#post-id-33604Comment by William Stein for <p>The problem is Python output buffering. Put <code>sys.stdout.flush()</code> after each print statement to ensure that the output is flushed to the output stream <strong>immediately</strong>, so you can see it then. The show command always flushes immediately, which is why it appears before.</p>
https://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/?comment=33637#post-id-33637I thought of an easy way to change SMC to have the behavior you expect and made a ticket: https://github.com/sagemathinc/smc/issues/594Thu, 02 Jun 2016 01:01:28 +0200https://ask.sagemath.org/question/33593/show-does-not-show-in-the-right-place/?comment=33637#post-id-33637