简体   繁体   中英

Python/Sage Graphing Error

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM