0

I'm writing a program that has 2 equations and when the first equation,x, becomes equal to 0, I want to graph the original points (which i have set as p and q) picked. My code looks like this:

for x in range (0,200):
    for y in range (0,200):
        p=x
        q=y
        c=0
        while (x > 0 and y > 0):
          i=x-y+100
          y=x+y-100
          c=c+1
          x=i
          if c > 1000:
              break
    if x < 0:
        plot((p,q))

It keeps giving me errors that look like this

WARNING: Output truncated!  

[<matplotlib.lines.Line2D object at 0x206b4f90>]
[<matplotlib.lines.Line2D object at 0x206b9110>]
[<matplotlib.lines.Line2D object at 0x206b9450>]
[<matplotlib.lines.Line2D object at 0x2008e3d0>]
[<matplotlib.lines.Line2D object at 0x206b9c50>]
[<matplotlib.lines.Line2D object at 0x206ba190>]

And dozens more of things that look just like the above

awaitkus
  • 3
  • 1
  • 3

1 Answers1

0

What you're getting is not an error. As your program runs, it calls the plot((p,q)) command many, many times, and for each time it's called, it prints [<matplotlib.lines.Line2D object at 0x206ba190>] or some variant thereof. This line is printed so many times that Sage truncates the output.

If your goal is to get a graph with each of these lines on the same coordinate plane, you need to do two things. First, you need to force Sage to combine each of your plots into a single image. At the top, add this line: plot_list = []. Then, replace plot((p,q)) with plot_list.append(plot((p,q))). Instead of trying to display the graphics objects as you generate them, this code stores them in a list. At the bottom, add sum(plot_list).show() outside of both loops. This combines all the graphs and tells Sage to display them. Second, this probably won't work in the Sage command line. In order to see the graph, you should use the notebook interface.

Matthew
  • 306
  • 4
  • 17
  • Now it is just giving me a bunch of weird graphs. I am in the notebook interface, no worries. – awaitkus Apr 08 '14 at 16:03
  • I'm pretty familiar with Sage, but I'm really not sure what you're trying to do mathematically. Would it be possible for you to post a link to a: what you're getting and b: an example of what you expect? Also, make sure that `sum(plot_list).show()` is fully outdented. It should not be inside either loop. I'll update my answer to make this clearer. – Matthew Apr 08 '14 at 18:07
  • May I ask what interface / product / API is being used in this example to access Sage? Is it publicly available? – Larry Lustig Apr 08 '14 at 18:20
  • 1
    Sage itself is free: [sagemath.org](http://sagemath.org). It sounds like awaitkus is using the notebook interface for that, either from a local copy or via an online server, for example [sagenb](http://www.sagenb.org/). You can also try [SageMath cloud](http://cloud.sagemath.com/) or the [Sage Cell Server](http://sagecell.sagemath.org). – John Palmieri Apr 08 '14 at 18:32