PDA

View Full Version : ParametricPlot and log scale axes in Mathematica


pastro
Oct5-09, 03:53 PM
Hello,

I have been trying to make a parametric plot with logarithmic axes in Mathematica, but have been unable to find an option to do this. Can someone tell me how to do this? My code is below, and for reference, EnergyScint[b] is the Bethe-Bloch equation for energy deposit for a fully ionized oxygen core passing through a 1/2 inch slab of scintillator, which I am plotting as a function of \beta \gamma

ParametricPlot[{b (1 - b^2)^(-1/2), EnergyScint[b]}, {b, .1, .999}, PlotRange -> All]

Thanks!

felipebm
Oct26-09, 11:00 AM
Hi,

I do not understand well the problem, but I suppose you are missing to apply the Log[] function to the functions which you want to plot logarithmically. Example:

ParametricPlot[{b (1 - b^2)^(-1/2), Log[10, EnergyScint[b]]}, {b, .1, .999}, PlotRange -> All]

This will create a SemiLog plot in which the Y axis will have logarithmic scale and the X axis will be linear.

Hope this helps!

pastro
Oct26-09, 02:23 PM
Thanks, but what I am really looking for is the tick marks to be logarithmically spaced, the same way LogPlot[] produces tick marks, but as a parametric plot. Your solution does not produce logarithmically scaled tick marks, just the log of the plotted variables on a linear scale.

After researching this issue, I am beginning to believe that Mathematica is unable to produce such a plot (at least, not simply...) and plotting the Log[] of the variables is indeed the only (highly non-ideal) solution.

Thanks!

felipebm
Oct26-09, 02:56 PM
Maybe this can help:
http://www-binf.bio.uu.nl/vitaly/mathematica/

I'd tried it with a simple function (10^x) by just replacing the Plot function with a ParametricPlot[{x,Log[10,10^x]},{x,0,10}] and it worked just fine.

Hope this does it.

felipebm
Oct26-09, 03:03 PM
This is the code as I use it:


(* Y-axis has log ticks *)

Clear[step,y1,y2,yticks,yticks2];

step=1; (* step in logs *)
y1=0; (* initial value with a label - log *)
y2=4; (* last value with a label - log *)


yticks=Join[Flatten[Table[Table[{Log[10,i],""},{i,10^j,10^(step+j),10^(j+(step-1))}],{j,y1,y2-step,step}],1],Table[{i,If[i==-1,"10^-1",If[i<0,("10^-")^-i,("10")^i]]},{i,y1,y2,step}]];


yticks2=Join[Flatten[Table[Table[{Log[10,i],""},{i,10^j,10^(step+j),10^(j+(step-1))}],{j,y1,y2-step,step}],1],Table[{i,""},{i,y1,y2,step}]];

ParametricPlot[{t, Log[10, 10^t]}, {t, 0, 10}, Frame -> {True, True, False, False}, FrameTicks -> {Automatic, yticks, {}, yticks2}, PlotRange -> {y1 - 0.00001`, y2}]

pastro
Oct26-09, 03:20 PM
Thanks, that seems to do the job!

felipebm
Oct26-09, 03:22 PM
You're welcome.

Anyway it shouldn't be that hard, isn't it? ;)