Function for 1-D plotting

asked 2012-07-06 01:12:36 +0200

jaia gravatar image

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 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 flag offensive close merge delete


Is there a question here? Maybe this should go to the sage-devel mailing list.

benjaminfjones gravatar imagebenjaminfjones ( 2012-07-06 03:03:20 +0200 )edit

Or maybe this code should go at ?

kcrisman gravatar imagekcrisman ( 2012-07-06 13:28:45 +0200 )edit

kcrisman, could you please put it there? There are an awful lot of hoops to jump through just to share a two-line function.

jaia gravatar imagejaia ( 2012-07-14 21:43:05 +0200 )edit

I've put it there. But if you want to be officially acknowledged for it if we use it, you may want to put your name there :)

kcrisman gravatar imagekcrisman ( 2012-07-16 10:26:33 +0200 )edit