What's happening actually has nothing to do with the string formatting (i.e. calling x = "blah %s" % YLabel
).
It's due to the way you initially define YLabel
.
For example, try doing:
x = "\rho"
print x
The "\r"
is interpreted as a carriage return and doesn't print. It just prints "ho". (This holds for a number of other escape sequences, e.g. \n
, \t
, \x
, \f
, \b
, etc.)
To avoid this, you either need to define the original string as a "raw" string:
x = r"\rho"
print x
or explicitly escape the "\r"
sequence:
x = "\\rho"
print x