2

For a multi-character subscript in Matplotlib, we should put all the characters inside curly braces. For example, if we want 123 as a subscript of N, we should use $N_{123}$. This is working fine as long as I am giving the subscript explicitly. But, my subscript is a variable (say, sub=123). So, when I use the format string method (shown below), all except the first character appear in normal size (shown in the figure).

sub = 123
plt.title("$N_{}$".format(sub))

Image shows only "1" becomes the subscript of N

JohanC
  • 71,591
  • 8
  • 33
  • 66
  • 3
    You need triple curly braces: `plt.title("$N_{{{}}}$".format(sub))`. See [this post](https://stackoverflow.com/questions/5466451/how-can-i-print-literal-curly-brace-characters-in-python-string-and-also-use-fo) – JohanC Mar 31 '20 at 21:50

1 Answers1

0

I had a similar issue, this worked out for me:

    title(r'Diffused Field for $\theta_{{out}}$ = {}°'.format(round(theta_out/pi*180,3)))