0
$\begingroup$

This might be trivial, but I am not able to get it. I am just keeping it simple.

Suppose I want to plot:

Plot[-x, {x, -1, 2}, Frame -> True]

enter image description here

Next if I want log scale on the Y axis, I am not getting the plot from -2 to 2, which is the range. I want to show those points in the plot, where the function is also negative. I know that Log[-quantity] is an imaginary number. Does it mean that when we have a minus value for the function, we can't use LogPlot?

LogPlot[x, {x, -2, 2}, Frame -> True]

enter image description here

How to get the -2 to 0 range of the function, in this case?

$\endgroup$
1
  • $\begingroup$ Huh?!? How do you plot -x and instead show a plot of +x?!? $\endgroup$ Aug 21 at 19:10
1
$\begingroup$

You can either plot the logarithm of the absolute value:

LogPlot[Abs[x], {x, -2, 2}]

Mathematica graphics

or use a symmetric logarithmic scale (symlog):

symlog = {
   Function[x, Sign[x]*Log[Abs[x] + 1]], 
   Function[y, Sign[y]*(Exp[Abs[y]] - 1)]};

Plot[x, {x, -200, 200}, ScalingFunctions -> symlog, 
 Ticks -> {Automatic, Flatten@Table[{10 ^i, -10 ^i}, {i, 0, 2}]}]

Mathematica graphics

$\endgroup$
0
$\begingroup$

How about

LogPlot[{x, -x}, {x, -2, 2}, Frame -> True]

enter image description here

$\endgroup$
0
$\begingroup$

I was expecting ReImPlot would handle ScalingFunctions to give the desired result, but the documentation for ReImPlot under Possible Issues says:

ScalingFunctions applies to the real and imaginary parts. 

So perhaps, something like this?

ReImPlot[Log[x], {x, -2, 2}, Frame -> True, 
 FrameTicks -> {{Quiet[
      Charting`ScaledTicks[{Log, Exp}][#1, #2, {6, 6}]] &, 
    Charting`ScaledFrameTicks[{Log, Exp}]}, {Automatic, Automatic}}]

enter image description here

$\endgroup$

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