Plot a vertical label in the y axis and LaTeX typesetting.

164 views
Skip to first unread message

Jose Guzman

unread,
Apr 15, 2009, 4:43:19 AM4/15/09
to Sage support
Hi there

I am trying to teach some simple principles of single compartment models
with sage and I plotted a couple of exponential equations in my notebook.

Although I got a nice x-axis () and other labels and similar things, I
cannot find a way to plot the y-axis in the vertical axis. Is there
anyway to do it?

You can take a look to my notebook to see what I mean
http://sagenb.org/home/pub/457

Another additional problem is that the LaTeX fonts are pretty small, and
I cannot represent Greek letters (like alpha, tau, pi,etc..) in the
labels (see the syntax bellow).

xlabel = text('Time (Units of $\tau$)',(3,-.10), rgbcolor='black')

This \tau does not show up in the graphic, but strange enough, this
works out of the box (pretty small though)

lnlabel = text('Unrecoverable fraction ($f_{U} = 1 -
f_{S}$)',(4,FS+.05),rgbcolor='black')

thank you very much in advance for your help and care!


Jose.

William Stein

unread,
Apr 15, 2009, 12:19:42 PM4/15/09
to sage-support
2009/4/15 Jose Guzman <n...@neurohost.org>:

Just one remar. There is a fontsize option to text:


xlabel = text('Time (Units of $\tau$)',(3,-.10), rgbcolor='black', fontsize=30)

William

William Stein

unread,
Apr 15, 2009, 12:19:44 PM4/15/09
to sage-support
2009/4/15 William Stein <wst...@gmail.com>:

The second remark is that backslash is an escape character for strings in
(almost) all programming languages. You have to do \\ to get a single
backslash, so this works:

xlabel = text('Time (Units of $\\tau$)',(3,-.10), rgbcolor='black', fontsize=30)

Or you can do:

xlabel = text(r'Time (Units of $\tau$)',(3,-.10), rgbcolor='black', fontsize=30)

Jose Guzman

unread,
Apr 15, 2009, 1:37:39 PM4/15/09
to sage-s...@googlegroups.com
Thank you very much for your remarks, everything worked fine, except for
that I did not manage to create a vertical oriented y-axis label. I
think the solution would be to import the matplotlib python module and
use it under Sage, however I did not find a proper manual to follow.

Thank you very much!

Jose.

William Stein

unread,
Apr 15, 2009, 1:56:20 PM4/15/09
to sage-s...@googlegroups.com

That might not be implemented yet in Sage directly.

> I
> think the solution would be to import the matplotlib python module and
> use it under Sage, however I did not find a proper manual to follow.

Here is how to use matplotlib directly in the Sage notebook:

import pylab as p
p.figure()
t = p.arange(0.01, 2.0, 0.01)
s = p.sin(2 * p.pi * t)
s = p.array([float(f(x)) for x in t])
P = p.plot(t, s, linewidth=4)
p.xlabel('time (s)'); p.ylabel('voltage (mV)')
p.title('Matlab-style plotting in Sage')
p.grid(True)
p.savefig('sage.png')

William Stein

unread,
Apr 15, 2009, 1:56:55 PM4/15/09
to sage-s...@googlegroups.com

The above example depends on a function f being defined, e.g.,

x = var('x')
f(x) = sin(3*x)*x+log(x) + 1/(x+1)^2

Jose Guzman

unread,
Apr 17, 2009, 4:44:07 PM4/17/09
to sage-s...@googlegroups.com
Thank you very much for your nice example. Actually I became confused
with all the backend stuff, but this example I realize how to use
matplotlib under Sage, although I have to admit I love the plotting
capabilities of Sage. Is there any way I can have a look to the code so
that I might try to implement some new characteristisc (like y-axis,
fontsize of the axis, etc...)

Thank you very very much!

Jose.

Jason Grout

unread,
Apr 18, 2009, 4:32:14 AM4/18/09
to sage-s...@googlegroups.com


Yes. In fact, the ability to look at the code is one of the main
reasons for Sage's existence! The code for plotting is in the directory:

$SAGE_ROOT/devel/sage/sage/plot/

where $SAGE_ROOT is the directory that contains the sage binary.

Thanks,

Jason

Jose Guzman

unread,
Apr 18, 2009, 8:05:42 AM4/18/09
to sage-s...@googlegroups.com

>
> Yes. In fact, the ability to look at the code is one of the main
> reasons for Sage's existence! The code for plotting is in the directory:
>
> $SAGE_ROOT/devel/sage/sage/plot/
>
> where $SAGE_ROOT is the directory that contains the sage binary.
>
> Thanks,
>
> Jason
>
>
>
Dear Jason,

thank you very much for the information!!!. I've just took a look to the
source code, and actually, much of what I wanted to do with the sage
plot is described in the Graphics class. There are still some things
which could be done (fonttype, log-scale, vertical ylabel, etc...) and I
heard somebody is working on that for the version 4.0. In any case, I
will try first to become more familiar with that and try to implement
some of my plot necessities after seen what is new for the new version.

Thank you very much for everything!!!

Jose.
> >
>

Reply all
Reply to author
Forward
0 new messages