Opened 12 years ago

# improve piecewise plotting — at Version 6

Reported by: Owned by: Karl-Dieter Crisman jason, was major sage-7.3 graphics piecewise David Joyner, Jason Grout, Robert Pollak, Karl-Dieter Crisman, Volker Braun, Samuel Lelièvre, Matthias Köppe, Eviatar Bach, Ralf Stephan N/A

Until we actually totally rewrite piecewise functions, we should improve some things.

For concreteness, here is one thing that should work but doesn't. I'm sure there are more - add to this list, and then whatever isn't fixed in this ticket can be moved to another ticket. I just want to make sure they're listed in one place, not ten tickets.

List:

• plotting more than one
```sage: f = Piecewise([[(0,1),x^3], [(1,2),x^2]], x)
sage: plot([f,x^3],(x,0,2))
```
A very similar example was at this ask.sagemath.org post:
```sage: f = Piecewise([[(-2,1),1],[(1,4),x]])
sage: g =  Piecewise([[(-2,1),1],[(1,4),2*x]])
sage: plot([f,g])
AttributeError: PiecewisePolynomial instance has no attribute '__float__'
```
• plotting a product of a piecewise with a symbolic (well, the problem is multiplying the two, but still worth putting here - see this sage-support thread)
• Maybe unify with `plot_step_function`, which currently is sort of its own thing?
• In this example:
```sage: zero_func(x)=0
sage: g = Piecewise([[(-1000,1),zero_func],[(1,1000),(x-1)^3]],x)
sage: G = g.plot()
sage: G.show(xmin=-5,xmax=5,ymax=100)
sage: g(1)
0
```
• You can use oo (infinity) for endpoints, but then the plot code for Piecewise gets screwed up.
• You can try putting in zero instead of defining this new zero function, but then g(1) and g(-1) etc. won't work.
• You can try using extend_by_zero to make the zero part, but it gives the same problem.
• You can plot without xmin and xmax, but that gives the whole function.
• You can plot without ymax, but that gives the range further out than you want.
• You can try plot(g), but that turns out to uncover a very strange error that may or may not be a bug.
• Most keywords are passed on to all component functions, but that is the wrong thing to do for legends. See this ask.sagemath.org question.

### comment:1 Changed 12 years ago by Karl-Dieter Crisman

Description: modified (diff)

### comment:2 Changed 12 years ago by Karl-Dieter Crisman

Description: modified (diff)

### comment:3 Changed 11 years ago by Karl-Dieter Crisman

Description: modified (diff)

### comment:4 Changed 11 years ago by Karl-Dieter Crisman

Description: modified (diff)

### comment:5 Changed 11 years ago by Karl-Dieter Crisman

Description: modified (diff)

Regarding the first item (can't plot two of them), It probably wouldn't even be that hard to fix. The problem is that `setup_for_eval_on_grid` wants to use `fast_float` but `Piecewise` guys don't have that, or more precisely don't have `__float__`.

### comment:6 Changed 11 years ago by Karl-Dieter Crisman

Description: modified (diff)
Note: See TracTickets for help on using tickets.