1 | initial version |
Quick and dirty, with a cleaned up sample dataset (I just added *s by hand, but there must be a smarter way to do that). See the output at http://www.sagenb.org/home/pub/4662/
x = var('x')
sample = [(1234, 1234), 0.0020259319286871956*x + 2.5]\
, [(1234, 1234), 0.0060777957860615869*x + 7.5]\
, [(1234, 1234), 0.010129659643435977*x + 12.5]\
, [(1234, 1244), 0.0156672069165316*x + 19.333333335]\
, [(1244, 1254), 0.015541264738745977*x + 19.333333335]\
, [(1254, 1264), 0.015417331208133968*x + 19.333333335]\
, [(1264, 1274), 0.015295358651107592*x + 19.333333335]\
, [(1274, 1312), 0.015175300890894815*x + 19.333333335]
def piecewiser(pieces):
p = 0
for i in pieces:
if i[0][0] == i[0][1]: #if this piece is a point
q = text("o", (i[0][0], i[1].substitute(x=i[0][0]))) #put an "o" at that point
else:
q = plot(i[1], (x, i[0][0], i[0][1])) #otherwise plot it as a function
if p == 0:
p = q
else:
p = p + q
return p
show(piecewiser(sample))