I am currently learning the basics of Mathematica. I can't seem to find a straightforward answer in the Wolfram documentation, probably for a lack of clarity in my queries.

For example, I want to plot $f=\frac{a}{x}$ with $x=\frac{y}{b}$, and manipulate the variable $y$, but obtain a graph with $x$ on the $x$-axis.

On Mathematica I would write:


This gives me the correct resulting plot but, of course, with the ticks'values of $y$ on the $x$-axis, instead of the ones of the dependent variable $x$. Do I need to change the ticks, or is there a more elegant way to achieve a plot with the values of $x$ on the $x$-axis?

Thank you.

  • 4
    $\begingroup$ Try with ParametricPlot reference.wolfram.com/language/ref/ParametricPlot.html $\endgroup$ – mattiav27 Sep 24 '18 at 18:30
  • $\begingroup$ I am not sure I understand this. You want x on the x axis and a/x on the y axis? Where does y and b come into this? $\endgroup$ – Hugh Sep 24 '18 at 18:52
  • $\begingroup$ @mattiav27 thank you! That's exactly what I was looking for. $\endgroup$ – bg_da Sep 24 '18 at 18:59
  • $\begingroup$ @Hugh Yes, x on the x-axis, and a/x on the y-axis. y is the only variable by which x depends on, as the values of a and b are known. What I needed was the ParametricPlot command. $\endgroup$ – bg_da Sep 24 '18 at 19:04

A static solution can be written like this:

With[{a = 1., b = .4, tmin = 0, tmax = 10},
  Block[{f, x, xticks},
    f[u_] := a/u;
    x[u_] := u/b; 
    xticks = {#, Round[x[#], .1]} & /@ Subdivide[tmin, tmax, 11];
    Plot[f[x[t]], {t, tmin, tmax},
      PlotRange -> {Automatic, {0, 3}},
      Ticks -> {xticks, Automatic}]]]


A more interesting dynamic solution looks like this:

With[{tmin = 0, tmax = 10},
    Dynamic @
      Plot[f[x[t]], {t, tmin, tmax},
        PlotRange -> {Automatic, {0, 3}},
        Ticks -> {xticks, Automatic}],
    {{a, 1.}, 0, 2, .1, Appearance -> "Labeled"},
    {{b, 1.}, .1, 2, .1, Appearance -> "Labeled"},
    {xticks, None},
    Initialization :> (
      f[u_] := a/u;
      x[u_] := u/b; 
      xticks := {#, Round[x[#], .1]} & /@ Subdivide[tmin, tmax, 11])]]



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.