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 =)
Loglog
-
- Site Admin
- Posts: 6305
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
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:
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)
-
- Site Admin
- Posts: 6305
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
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)"
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)"