Page 1 of 1


Posted: Thu Oct 25, 2007 5:33 am
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 =)

Posted: Thu Oct 25, 2007 10:30 am
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.


Code: Select all

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

objref g
g = new Graph()
logy.plot(g, logx)

Posted: Fri Oct 26, 2007 3:58 am
by Vincent d
Thank you for your response Ted, I'll do like that.


Posted: Mon Jan 28, 2008 7:10 pm
by jaambros
Is there a simple way to get the axes labels right when plotting as you suggest?


Posted: Tue Jan 29, 2008 9:26 am
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)"