Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

plotting multiple functions from a for loop

Here I link to a worksheet with which I'm having the darnedest trouble...

PlotTest

The code in the worksheet makes it easy to plot many similar plots, and this is a pretty organized way to do it. I got it to work once, but I changed something and made too many changes afterward to get it working again to undo back to my original code.

The problem is in the third cell, obviously. I want to assign to 'a' "plot all of the functions in the list funclist." I realize that they aren't functions, really (they aren't assigned names such as f0,f1,f2, etc), but I'll try to solve that another day. But anyway, how can I set this loop up to add all of these plots and dump them into an object? I need to be able to input 'a' and get a plot containing all of these.

As is evident from the worksheet, I can't use the operator += (though I swear I did the first time).

I would rather not to do it like this:

a = plotlist[0]
for i in range(1,10):
    a += funclist[i]

Because that requires that I spread out the definition of 'a'. However, that seems to be the easiest way to do it.

But I would like to be able to do it in two lines of code --- for i in range, add all these plots to this object.

plotting multiple functions from a for loop

Here I link to a worksheet with which I'm having the darnedest trouble...

PlotTest

The code in the worksheet makes it easy to plot many similar plots, and this is a pretty organized way to do it. I got it to work once, but I changed something and made too many changes afterward to get it working again to undo back to my original code.

The problem is in the third cell, obviously. I want to assign to 'a' "plot all of the functions in the list funclist." I realize that they aren't functions, really (they aren't assigned names such as f0,f1,f2, etc), but I'll try to solve that another day. But anyway, how can I set this loop up to add all of these plots and dump them into an object? I need to be able to input 'a' and get a plot containing all of these.

As is evident from the worksheet, I can't use the operator += (though I swear I did the first time).

I would rather not to do it like this:

a = plotlist[0]
for i in range(1,10):
    a += funclist[i]
plotlist[i]

Because that requires that I spread out the definition of 'a'. However, that seems to be the easiest way to do it.

But I would like to be able to do it in two lines of code --- for i in range, plotlist, add all these plots to this object.

plotting multiple functions from a for loop

Here I link to a worksheet with which I'm having the darnedest trouble...

PlotTest

The code in the worksheet makes it easy to plot many similar plots, and this is a pretty organized way to do it. I got it to work once, but I changed something and made too many changes afterward to get it working again to undo back to my original code.

The problem is in the third cell, obviously. I want to assign to 'a' "plot all of the functions in the list funclist." I realize that they aren't functions, really (they aren't assigned names such as f0,f1,f2, etc), but I'll try to solve that another day. But anyway, how can I set this loop up to add all of these plots and dump them into an object? I need to be able to input 'a' and get a plot containing all of these.

As is evident from the worksheet, I can't use the operator += (though I swear I did the first time).

I would rather not to do it like this:

a = plotlist[0]
for i in range(1,10):
range(1,len(plotlist)):
    a += plotlist[i]

Because that requires that I spread out the definition of 'a'. ' and has an unnecessary amount of code. However, that seems to be the easiest way to do it.

But I would like to be able to do it in two lines of code --- for i in plotlist, add all these plots to this object.

click to hide/show revision 4
added to end, fixed erroneous code

plotting multiple functions from a for loop

Here I link to a worksheet with which I'm having the darnedest trouble...

PlotTest

The code in the worksheet makes it easy to plot many similar plots, and this is a pretty organized way to do it. I got it to work once, but I changed something and made too many changes afterward to get it working again to undo back to my original code.

The problem is in the third cell, obviously. I want to assign to 'a' "plot all of the functions in the list funclist." I realize that they aren't functions, really (they aren't assigned names such as f0,f1,f2, etc), but I'll try to solve that another day. But anyway, how can I set this loop up to add all of these plots and dump them into an object? I need to be able to input 'a' and get a plot containing all of these.

As is evident from the worksheet, I can't use the operator += (though I swear I did the first time).

I would rather not to do it like this:

a = plotlist[0]
for i in range(1,len(plotlist)):
    a += plotlist[i]

Because that requires that I spread out the definition of 'a' and has an unnecessary amount of code. However, that seems to be the easiest way to do it.

But I would like to be able to do it in two lines of code --- for i in plotlist, add all these plots to this object.object. Or three lines, if I have to initialize 'a' beforehand (give it a type or whatever.)