| 1 | initial version |
Good question.
The reason for this behavior is that ymax and friends are not in fact parameters for plot, but for show; we just pass those parameters on to show(). Presumably we overwrite them - you can verify this by looking at the output of this.
sage: p+q
sage: q+p
I don't see an obvious way to fix this without rewriting the code substantially. However, this may work as a workaround for you.
sage: p1 = line([(a,b) for a,b in zip(p[0].xdata,p[0].ydata) if (b>=-1 and b<=1)]) sage: q1 = line([(a,b) for a,b in zip(q[0].xdata,q[0].ydata) if (b>=0 and b<=4)]) sage: p1+q1
We're using the fact that a Graphics object has various subobjects, and for a basic plot there is one of them which we access as the "zeroth" one, and its xdata and ydata are hopefully self-explanatory. Then we use a Python list comprehension and create a line from that data, which after all is what a plot of a function turns out to be.
Good luck!
| 2 | No.2 Revision |
Good question.
The reason for this behavior is that ymax and friends are not in fact parameters for plot, but for show; we just pass those parameters on to show(). Presumably we overwrite them - you can verify this by looking at the output of this.
sage: p+q
sage: q+p
I don't see an obvious way to fix this without rewriting the code substantially. However, this may work as a workaround for you.
sage: p1 = line([(a,b) for a,b in zip(p[0].xdata,p[0].ydata) if (b>=-1 and b<=1)])
sage: q1 = line([(a,b) for a,b in zip(q[0].xdata,q[0].ydata) if (b>=0 and b<=4)])
sage: We're using the fact that a Graphics object has various subobjects, and for a basic plot there is one of them which we access as the "zeroth" one, and its xdata and ydata are hopefully self-explanatory. Then we use a Python list comprehension and create a line from that data, which after all is what a plot of a function turns out to be.
Good luck!
| 3 | No.3 Revision |
Good question.
The reason for this behavior is that ymax and friends are not in fact parameters for plot, but for show; we just pass those parameters on to show(). Presumably we overwrite them - you can verify this by looking at the output of this.
sage: p+q
sage: q+p
I don't see an obvious way to fix this without rewriting the code substantially. However, this may work as a workaround for you.
sage: p1 = line([(a,b) for a,b in zip(p[0].xdata,p[0].ydata) if (b>=-1 and b<=1)])
sage: q1 = line([(a,b) for a,b in zip(q[0].xdata,q[0].ydata) if (b>=0 and b<=4)])
sage: p1+q1

We're using the fact that a Graphics object has various subobjects, and for a basic plot there is one of them which we access as the "zeroth" one, and its xdata and ydata are hopefully self-explanatory. Then we use a Python list comprehension and create a line from that data, which after all is what a plot of a function turns out to be.
Good luck!
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.