1
$\begingroup$

I am calling $y_{n}=x^{n}$ and I want to plot $ln(y_{n})$ for a number of different integer values of $n$ (I know this is very simple- it's actually a much simpler version of what I'm actually trying to do). If I execute

Table[Plot[Log[x^n], {x, 0, 1}, 
  AxesLabel -> {"x", "ln(" Subscript[y, n] ")"}], {n, 1, 3}]

the final part of the $y$ axis label moves to the front. Is there any way to avoid this whilst also properly displaying the subscript. Thanks in advance for any help.

$\endgroup$
2
  • 3
    $\begingroup$ That's because you are effectively multiplying the strings by the Subscript expression, since they are separated by a space. Use Row[{"ln(", Subscript[y, n], ")"}] instead instead of your "ln(" Subscript[y, n] ")". $\endgroup$
    – MarcoB
    Commented Dec 29, 2020 at 15:59
  • $\begingroup$ Alternatively, you can use StringForm, e.g., Plot[Evaluate[Log[x^#] & /@ Range[3]], {x, 0, 1}, AxesLabel -> {"x", StringForm["ln(``)", Subscript[y, n]]}, PlotLegends -> Placed[StringForm["n = ``", #] & /@ Range[3], {.7, .4}]] $\endgroup$
    – Bob Hanlon
    Commented Dec 29, 2020 at 16:15

3 Answers 3

3
$\begingroup$

Here are two solutions.

GraphicsRow @
 Table[
   Plot[Log[x^n], {x, 0, 1}, 
     AxesLabel -> {"x", Row[{"ln(", Subscript[y, n], ")"}]}],
   {n, 3}]

and

GraphicsRow @
  Table[
    Plot[Log[x^n], {x, 0, 1}, AxesLabel -> {"x", ln[Subscript[y, n]]}],
    {n, 3}]

Both give

plots

The solution using Row is more generally applicable and is the one I recommend. The other solution works because ln is not a defined symbol.

$\endgroup$
0
$\begingroup$

HoldForm[] will keep the parentheses from moving around.

    Table[Plot[Log[x^n], {x, 0, 1},AxesLabel -> {"x", HoldForm["ln(" Subscript[y, n] ")"]}], {n, 1, 3}]
$\endgroup$
0
$\begingroup$
Table[Plot[Log[x^n], {x, 0, 1}, 
  AxesLabel -> {"x", 
    ToString["Ln"] ~~ ToString["("] ~~ 
     ToString@TraditionalForm[Subscript[y, n]] ~~ ToString[")"]}], {n,
   1, 3}]

graphics row with correct display

$\endgroup$

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