Opened 3 years ago
Last modified 3 years ago
#21618 needs_work defect
plot in piecewise regression
Reported by:  kcrisman  Owned by:  

Priority:  minor  Milestone:  sage7.4 
Component:  symbolics  Keywords:  
Cc:  paulmasson  Merged in:  
Authors:  Reviewers:  
Report Upstream:  N/A  Work issues:  
Branch:  u/rws/216181 (Commits)  Commit:  c008c29052c1c035d1c555503c823053a77955dd 
Dependencies:  Stopgaps: 
Description (last modified by )
P = piecewise([((0,2),x),((2,6),2)]) print P plot(P)
Before this would have plotted the whole thing, now it defaults to the usual plotting only from 1 to 1 (which of course gives an error).
Moreover pieces are joined and detect_poles=True
option skips the origin for no good reason:
P = piecewise([((1,2),x),((2,5),1)]) print P plot(P, 1, 5, detect_poles=True)
Change History (12)
comment:1 Changed 3 years ago by
 Cc paulmasson added
 Description modified (diff)
comment:2 Changed 3 years ago by
 Summary changed from plot in piecewise regression (?) to plot in piecewise regression
comment:3 Changed 3 years ago by
Correct. So it would be nice to emulate that so everyone's code doesn't break  I had a notsonice time drawing graphs on the fly in class today because of this. It seems reasonable, since piecewise is an unusual situation.
comment:4 Changed 3 years ago by
 Branch set to u/rws/plot_in_piecewise_regression
comment:5 Changed 3 years ago by
 Commit set to c98505b6541783a93eaa84721f564bd1e311285b
 Status changed from new to needs_review
Oops I just saw the second complaint. This will not be as easy.
New commits:
c98505b  21618: plotting piecewise without need of giving domain interval

comment:6 Changed 3 years ago by
 Status changed from needs_review to needs_work
comment:7 Changed 3 years ago by
Note that your command plot(P, 1, 5, detect_poles=True)
also does not work on Sage7.1, i.e., the old piecewise, and plot(P, detect_poles=True)
also has a gap at x=0
. So, this particularly is rather an enhancement of plot
, not a bug in piecewise
.
comment:8 Changed 3 years ago by
 Branch changed from u/rws/plot_in_piecewise_regression to u/rws/216181
comment:9 Changed 3 years ago by
 Commit changed from c98505b6541783a93eaa84721f564bd1e311285b to c008c29052c1c035d1c555503c823053a77955dd
 Status changed from needs_work to needs_review
New commits:
c008c29  21618: plotting piecewise without need of giving domain interval

comment:10 Changed 3 years ago by
 Status changed from needs_review to needs_work
 Why there is commented code? Reference to some ticket explaining stuff is fine, but not strange imports etc.
 Why there is extra printing of pieces???
 If I do specify the domain, then each piece is plotted over this domain!
I'll see if I can resolve all this in the next hour or so.
comment:11 Changed 3 years ago by
Address 1&2 and simplify a bit to get
def plot(cls, self, parameters, variable, *args, **kwds): from sage.plot.all import plot, Graphics g = Graphics() for (dom, fun) in self.items(): g += plot(fun, (variable, dom.inf(), dom.sup()), *args, **kwds) # If it's the first piece, pass all arguments. Otherwise, # filter out 'legend_label' so that we don't add each # piece to the legend separately (trac #12651). kwds.pop('legend_label', None) return g
3 is tricky, however, because of a variety of ways to pass left and right bounds. I think we should factor out the logic of getting these bounds into a separate function which will say always set xmin/xmax
keywords, then we can call this function in the top level plot
as well as plot
methods and have a guaranteed uniform behavior. Thoughts?
There is also
 No documentation and examples at all!!!
comment:12 Changed 3 years ago by
Andrey, please go ahead with your own branch, the plotting code is quite opaque and uninteresting to me, and I'm into other projects right now.
The old
Piecewise
has a custom plot method. This method is omitted in the currentpiecewise
.