Ask Your Question

plotting multiple functions from a for loop

asked 2019-04-25 04:06:52 -0500

thetha gravatar image

updated 2019-04-25 05:07:23 -0500

This solution: is not working any more

The error is:

Error in lines 3-3
Traceback (most recent call last):
  File "/cocalc/lib/python2.7/site-packages/smc_sagews/", line 1188, in execute
    flags=compile_flags) in namespace, locals
  File "", line 1, in <module>
  File "/ext/sage/sage-8.7_1804/local/lib/python2.7/site-packages/sage/misc/", line 492, in wrapper
    return func(*args, **options)
  File "/ext/sage/sage-8.7_1804/local/lib/python2.7/site-packages/sage/plot/", line 1956, in plot
    G = _plot(funcs, (xmin, xmax), **kwds)
  File "/ext/sage/sage-8.7_1804/local/lib/python2.7/site-packages/sage/plot/", line 2224, in _plot
    legend_label=legend_label_entry, legend_color=legend_color_entry, **options_temp)
  File "/ext/sage/sage-8.7_1804/local/lib/python2.7/site-packages/sage/misc/", line 492, in wrapper
    return func(*args, **options)
  File "/ext/sage/sage-8.7_1804/local/lib/python2.7/site-packages/sage/plot/", line 1941, in plot
    G = funcs.plot(*args, **original_opts)
TypeError: plot() takes exactly 1 argument (17 given)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-04-25 12:33:43 -0500

dsejas gravatar image

Hello, @thetha. The problem is that

plotlist = [f.plot((x, 1, 10)) for f in funclist]

defines a list of Sage plots. You can verify this by writing


You should get:

<type 'list'>
<class ''>

What you need is just one Sage plot, i.e., a <class ''>, like any of the plotlist[i].

The solution is the following:

funclist = [1/x^i for i in range(10)]
plotlist = sum(f.plot((x, 1, 10)) for f in funclist)

This way, instead of creating a list of plot, you sum all the plots together, which is equivalent to superimpose them in a single image. You can verify this by typing again:


(This time you will get <class ''>, as desired.)

The result should look like this: image description

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-04-25 04:06:52 -0500

Seen: 45 times

Last updated: Apr 25