Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-character subscript in Matplotlib when the subscript is a variable

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

like image 595
ukbasak Avatar asked May 16 '26 15:05

ukbasak


1 Answers

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

    title(r'Diffused Field for $\theta_{{out}}$ = {}°'.format(round(theta_out/pi*180,3)))
like image 106
Hussein Avatar answered May 19 '26 04:05

Hussein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!