Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib axis label: \theta does not work \Theta does

Tags:

I have a weird behaviour in matplotlib. Using the following I get a nice and shiny big theta. As soon as I use \theta instead of \Theta I get

heta

as an axis label

plt.figure(**pd.figpropsHP) line=pd.lineCycler() for i in range(2):     for j in range(length-1):         velocity[i,j]=(velocity[i,j+1]-velocity[i,j])*1000 #multiplied with sampling rate     plt.plot(velocity[i,startstop[0]:startstop[1]],**next(line))           #plt.show(pPosition) plt.xlabel("t[ms]")     plt.ylabel("$\dot{\Theta}$[deg/s]")   plt.ylim(-3000,-3000+yrangeV) plt.annotate('30ms',fontsize='9', xy=(30, -1000),xytext=(40, -1000),verticalalignment='center',arrowprops=myarrow) plt.annotate('8ms',fontsize='9', xy=(8, -1700),xytext=(40, -1700),verticalalignment='center',arrowprops=myarrow) plt.axvline(x=span2Stop,lw='0.3',c='0.5') plt.axvspan(spanStart, spanStop, facecolor='0.9', alpha=1,edgecolor='0.9',lw=0) plt.tight_layout() plt.savefig(imagePath + "collisionTestbedVmot.pdf") 

Any ideas what I am doing wrong? I sadly do not have any time to start fancy stuff (latex integration etc.). Can I use an utf8 character instead? How do I get one?

like image 802
louis cypher Avatar asked Apr 29 '12 08:04

louis cypher


People also ask

What is θ in Python?

Theta (𝜭) is very often used greek mathematical letters and has a higher repetition in probability. In this article, we are going to add 𝜭 using a command in matplotlib. plt.text(3, 0.4, r'$\theta=100$') #Adding 𝜭 as text. plt.title('Errorbar with 'r'$\theta=100$') #Adding 𝜭 in title of the figure.

How do I change the axis label size in Matplotlib?

If we want to change the font size of the axis labels, we can use the parameter “fontsize” and set it your desired number.


2 Answers

If you specify that the string is raw text (a r before the quotation mark), it works. Like this:

plt.ylabel(r"$\dot{\Theta}$[deg/s]") 

The reason you got an unexpected result is that \t means a tab. So if you type \theta, it is parsed as \t and following heta. If you specify it a a raw string, backslashes and python escapes will not be treated.

If you don't use raw strings, you have to escape the backslash (\\) so python treats it as a backslash and not as a tab symbol (so as \theta and not as \t and heta). That's why \\theta did the job. To avoid always have to write double backslashes, use raw strings when using latex, since it uses backslashes a lot for special characters.

like image 161
joris Avatar answered Dec 08 '22 00:12

joris


using \\theta did the job. Anyway this is really a strange behaviour that, in my eyes, should be fixed to do it or not no matter whether it is \theta or \Theta. Any thoughts about that?

like image 31
louis cypher Avatar answered Dec 07 '22 23:12

louis cypher