Loglog

Anything that doesn't fit elsewhere.
Post Reply
Vincent d
Posts: 12
Joined: Fri Oct 12, 2007 4:30 am
Location: Lausanne

Loglog

Post by Vincent d »

Hello everyone,

Does anyone know how to plot a vector with a logarithmic scale, similarly as would do the matlab loglog function?

I haven't found any clue in the documentation neither in the forum.

Any ideas are welcome =)
ted
Site Admin
Posts: 6305
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Post by ted »

Assuming that your (x,y) data are stored in two Vectors xvec and yvec, the steps are:
copy xvec and yvec to a new pair of Vectors (so you don't destroy the original values)
apply natural log or log10 to both of the new Vectors
use the Vector class's plot() method as usual

It just happens that the Vector class has two methods, called log and log10, which
combine the first two steps.

Example:

Code: Select all

objref logx, logy
logx = new Vector()
logy = new Vector()
logx.log(xvec) // natural log
logy.log(yvec)

objref g
g = new Graph()
logy.plot(g, logx)
Vincent d
Posts: 12
Joined: Fri Oct 12, 2007 4:30 am
Location: Lausanne

Post by Vincent d »

Thank you for your response Ted, I'll do like that.

=)
jaambros
Posts: 29
Joined: Tue Oct 04, 2005 3:29 pm
Location: Ohio University

Post by jaambros »

Is there a simple way to get the axes labels right when plotting as you suggest?

Thanks,
Jose
ted
Site Admin
Posts: 6305
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Post by ted »

If by "right" you mean "display 1 10 100 etc. at major tics, and perhaps 3 30 300 at minor tics"
the answer is no. The Graph class does not have a method for doing that. But it should be
fairly straigthforward, if tedious, to cobble up something that does the job by using xaxis(3)
yaxis(3) to suppress the "automatic" x and y axes, then beginline() and line() with
appropriate args to draw the custom axes and tic marks, and finally label() with appropriate
args to write the numeric values next to the tics.

I'd simply stick with the automatic axes, and print a label on the graph's canvas to remind
viewers that the plotted values are logarithms, e.g.
g.label(0.5, 0.9, "log(foo) vs. log(fap)"
Post Reply