# Function for 1-D plotting

Not sure where to post this, so here goes.

I have to do quite a bit of 1-D plotting to explain local stability analysis. The code at http://trac.sagemath.org/sage_trac/ti... works but labeling specific points is close to impossible because of the way Sage adjusts the aspect ratio. So I put together a simple function that plots a line and two invisible points, allowing me to know where things are going to go (and making a long list of plot commands a bit neater). Here's the code.

def plot_1d(xmin, xmax, ymin=-1, ymax=1):
p=plot((ymax+ymin)/2, (xmin, xmax), color="black", axes=False) + point((0,ymax), color="white") + point((0,ymin), color="white")
return p


And here's how I'm using it.

plot_1d(-1,1200,-1,1) + point((0,0), color="black", size=20) + text("0", (0,-0.05), color="black") + point((1000,0), color="black", size=20) + text("K", (1000,-0.05), color="black") + arrow((700, 0), (1000,0)) + arrow((0, 0), (300,0)) + arrow((350, 0), (650,0)) + arrow((1100, 0), (1000,0))

edit retag close merge delete