2

how can i exchange x and y Axis of this loglogplot?

x1[y_] := y+3
x2[y_] := y-1

myplot = LogLogPlot[{x1[y], x2[y]}, {y, 10^-4, 100}, PlotRange -> Full, 
  PlotPoints -> 10, PlotLegends -> "Expressions", ImageSize -> 600, 
  AspectRatio -> Full, Filling -> None]

this is a simple example, my real functions of X are very complicated and i can not find Y with explicit function of x.

  1. Is there any way to switch the axis of this LogLogPlot?

  2. How can I export this plot data point in a matrix?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Alex
  • 21
  • 1

2 Answers2

4

This works for your example:

 y1 = InverseFunction[FunctionInterpolation[x1[y], {y, 10^-4, 100}]]
 y2 = InverseFunction[FunctionInterpolation[x2[y], {y, 10^-4, 100}]]
 LogLogPlot[{y1[x],y2[x]}, {x, 10^-3, 100}]

However I'm afraid FunctionInterpolation might not do a good job of sampling depending on your function.

You can do this:

 y1 = InverseFunction[x1]
 y2 = InverseFunction[x2]
 LogLogPlot[{y2[x], y1[x]}, {x, 10^-3, 100}]

But it might be painfully slow as it effectively iterates to find every plot point.

Here is a bit of a hack to fix the axes after using axisFlip: (LogLogPlot does something weird with PlotRange so you can't simply transpose the range as axisFlip does )

(https://mathematica.stackexchange.com/a/18669/2079)

Show[LogLogPlot[ Null, {x, 3, 100},
   PlotRange -> {{10^-3, 100}, {10^-4, 100}}], myplot // axisFlip]

enter image description here

george2079
  • 38,913
  • 1
  • 43
  • 110
  • i couldn't use of axisFlip, the error is: "Could not combine the graphics objects in Show" – Alex Jul 24 '15 at 19:27
  • you need to copy and evaluate the definition of axisFlip from the linked answer. – george2079 Jul 24 '15 at 19:32
  • Wow, It works! you are lifesaving! – Alex Jul 24 '15 at 19:41
  • @george209 Very nice! Could you elaborate on the "hack" required for LogLogPlot. It looks like maybe you are plotting nothing (Null) but setting the Axis needed for the flipped plot. Would you have to do something like this for LogPlot and LogLinearPlot as well? – Jack LaVigne Jul 25 '15 at 02:01
4

Use ListLogLogPlot with a list of values for from your functions.

points = Transpose[{{x1[#], #}, {x2[#], #}} & /@ Range[10^-4, 100, (100 - 10^-4)/200]];

ListLogLogPlot[points, Joined -> True]

enter image description here

I've used 200 plot points to get a nice smooth plot.

Hope this helps.

Edmund
  • 42,267
  • 3
  • 51
  • 143