Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Latex and text in matplotlib title

I'm trying to show an image with a title that combines normal text with a couple of Latex commands:

plt.imshow(w1subtracted2, origin='lower',
          extent=[l_max, -l_max, -b_max, b_max],
          cmap = color_map)
plt.title('W1 disk and central $\pm2\textdegree$ subtracted', fontsize = 'small')
plt.xlabel(xlabel, fontsize = 'small')
plt.ylabel(ylabel, fontsize = 'small')
plt.savefig('w1subtracted2.png')

but I can't get the title showing the \pm and \textdegree to show in Latex style. How can I achieve that?

like image 964
Jim421616 Avatar asked Oct 11 '17 23:10

Jim421616


Video Answer


1 Answers

It seems you are not using latex (usetex = True) but simple MathText. There is no \textdegree in MathText.

Using

plt.title(r'W1 disk and central $\pm2^\circ$ subtracted', fontsize='small')

should give you

enter image description here

like image 69
ImportanceOfBeingErnest Avatar answered Sep 29 '22 03:09

ImportanceOfBeingErnest