6
$\begingroup$

I have a function defined in 3D and I want to plot it in such a way that first and third component are in LogLog scale. So if I reduce to 2D I could plot my function using LogLogPlot but I need 3d version. I tried this:

f1 = {x, 1, x^2}
a3 = ParametricPlot3D[f1, {x, 1, 80}, AxesLabel -> {"x", "z", "y"}, 
ScalingFunctions -> {"Log", Identity, "Log"}, 
BoxRatios -> {1, 1, 3}, ViewPoint -> {0, -2, 0}, 
PlotRange -> {0.001, 2}, LabelStyle -> Directive[Black, Bold]]

However this plot clearly has linear scales and only function is rescaled. What I want to achieve: Suppose I have

 LogLogPlot[x^2,{x,1,50}] 

with nice logarithmic axes and I want to add that third component corresponding to z axis and then plot my function in 3d with x and y axes corresponding to the function $y=x^2$ in LogLog scale and component z in linear. How can I improve this code to do that?

$\endgroup$
5
$\begingroup$

ScalingFunctions isn't documented to work with ParametricPlot3D, which is why it shows up in red in the plotting command. But it does seem to work halfway, by transforming the function but doing nothing for the tick marks.

You can supply the tick marks manually, but that means you have to do so every time. The excellent CustomTicks package can be of help, but I haven't kept up with it so I don't know how well it works with newer versions of Mathematica. Here I'm going to use the undocumented Charting`ScaledTicks function, which has been exposed here on the SE before.

f1[x_] := {x, 1, x^2}
a3 = ParametricPlot3D[f1[x], {x, 1, 80},
  AxesLabel -> {"x", "y", "z"},
  ScalingFunctions -> {"Log", Identity, "Log"},
  BoxRatios -> {1, 1, 1},
  Ticks -> {
    Charting`ScaledTicks[{Log, Exp}],
    Automatic, 
    Charting`ScaledTicks[{Log, Exp}]
    }]

enter image description here

$\endgroup$
  • $\begingroup$ Should Charting`ScaledTicks work without the package you mentioned? I can't compile this code in my version 10.3. It gives me error: "Tick specification must be a list or a function" $\endgroup$ – Caims Jan 3 '17 at 16:24
  • $\begingroup$ @Caims - apparently using the string as an input for the ticks was added in version 11. Updating post so that it will work in version 10.3.1 also. And no, you don't need to use the external package, I just linked it for information purposes. $\endgroup$ – Jason B. Jan 3 '17 at 16:27
  • $\begingroup$ It works with data too, and indeed works as it's supposed to. Thank you! $\endgroup$ – Caims Jan 3 '17 at 16:37
2
$\begingroup$

I suppose it's always possible to do this yourself using Ticks. I agree this would be a useful function though.

This is a quick way to get what would be, I guess, a LogLinearLogPlot using what you had already:

f1 = {x, 1, x^2};
logXTicks = {1. Log10[#], #} & /@ 
   Join[Range[.1, 1, .1], Range[1, 7, 2], Range[10, 100, 35]];
logZTicks = {1. Log10[#], #} & /@ 
   Join[Range[.1, 1, .1], Range[1, 8, 2], Range[10, 90, 10]];
a3 = ParametricPlot3D[
  ReplacePart[f1, {
    1 -> Log10[f1[[1]]],
    3 -> Log10[f1[[3]]]
    }],
  {x, 1, 80},
  AxesLabel -> {"x", "z", "y"},
  BoxRatios -> {1, 1, 3},
  ViewPoint -> {0, -2, 0},
  PlotRange -> {0.001, 2},
  Ticks -> {logXTicks, Automatic, logZTicks},
  LabelStyle -> Directive[Black, Bold]]
$\endgroup$
  • $\begingroup$ Unfortunately, when I try to draw more complicated function X axis doesn't work properly: X axis ticks shrink to one point, and it doesn't work properly with data too. For example if I try {x,1,1.1102411875245117 (1/x)^1.2542211266950642} with PlotRange -> {{1, 80}, {0, 2}, {0.00001, 2}} it doesn't look like it's supposed to. I probably don't understand how your code rescales axes, hence the problem with data too since my data matches this function. Could you explain ? $\endgroup$ – Caims Jan 3 '17 at 12:01
  • $\begingroup$ I'm doing the ticks largely by hand (figuring out what works well for the range manually), although it wouldn't be a killer to write autocomputed tick code. Basically what you would do is take linearly spaced ranges and then take the log of each point but label it with the original point and then determine which ranges would work well from the plot range supplied. $\endgroup$ – b3m2a1 Jan 3 '17 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.