From: Dan R. <xa...@ya...> - 2008-06-10 19:15:12
|
Hopefully I won't become a nuisance in my quest to become adept with PyX. : ) My question this time is what is the preferred method to plot a piecewise function? For instance, the function I want to plot at the moment is: $$ f(x) = \left\{ \begin{array}{ll} x & 0 \leq x < 1 \\ 0 & x = 1 \\ 1 & 1 < x \leq 2 \\ 3 - x & 2 < x < 3 \\ 1 & 3 \leq x \leq 4, x \neq 3.5 \\ 2 & x = 3.5 \\ \end{array}\right. $$ but a much simpler example/explanation would be more than enough for me. Thanks again, -Daniel |
From: Alan G I. <ai...@am...> - 2008-06-10 19:49:39
|
On Tue, 10 Jun 2008, Dan Reinholz apparently wrote: > My question this time is what is the preferred method > to plot a piecewise function? No claim of expertise, but ... Generate the data, and plot each piece separately. (Duplicating endpoints.) hth, Alan Isaac |
From: Stefan S. <Ste...@ph...> - 2008-06-11 06:58:15
|
Am Dienstag 10 Juni 2008 21:15 schrieb Dan Reinholz: > My question this time is what is the preferred method > to plot a piecewise function? As Alan said you can plot the pieces separately. Another possibility is to define your function as in python and then plot this function as below. # --------------------------------------------------------------- def f(x): if x<0: return 1 else: return 1+x g = graph.graphxy(width=8, x=graph.axis.linear(min=-2, max=2), y=graph.axis.linear(min=-0, max=3)) g.plot(graph.data.function("y(x)=f(x)", context=locals())) # --------------------------------------------------------------- Ciao, Stefan |