0
$\begingroup$

I searched many times but could get a simple way to get my desired output. The problem is this: In creating ListPlot, and using ```LegendLable`` like

LegendLabel -> Placed[Subscript[x, y] "for a=", Above]

why I am getting the output as "for a= Subscript[x, y]" and not "Subscript[x, y] for a= ". What could be a simple solution for it? I tried "ToString" also like

Placed[Subscript[x, y]<>ToString[ "for a="], Above]

But no success.

$\endgroup$
4
  • 1
    $\begingroup$ Placed[ToString[Subscript[x, y] // TraditionalForm ] <> ToString["for a="], Above]? $\endgroup$
    – cvgmt
    Oct 24, 2022 at 15:42
  • $\begingroup$ LegendLabel -> Placed[StringForm["`` for a=", Subscript[x, y]], Above] $\endgroup$
    – Bob Hanlon
    Oct 24, 2022 at 23:29
  • $\begingroup$ Many thanks, @cvgmt. It solved the issue. $\endgroup$ Oct 25, 2022 at 18:16
  • $\begingroup$ Thanks, @BobHanlon. It also worked. $\endgroup$ Oct 25, 2022 at 18:16

1 Answer 1

1
$\begingroup$

Let's look at the inner expression:

Subscript[x, y] "for a="

Mathematica is going to interpret this as multiplication (the expression is syntactically incorrect as it stands, so Mathematica will default to considering juxtaposed expressions as representing a multiplication):

Subscript[x, y] "for a=" // FullForm
(* Times["for a=", Subscript[x, y]] *)

Mathematica has specific rules for how to normalize arithmetic expressions (i.e. how to order the arguments). What you want to do is choose a construct for placing expressions into a particular arrangement. There are many of these, but maybe the one you want is Row:

Row[{Subscript[x, y], "for a="}, " "]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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