在python p中插入度符号

2024-05-18 12:33:34 发布

您现在位置:Python中文网/ 问答频道 /正文

这是一个很简单的问题,但我却不知道。我只是想在我的python绘图的标题和图例中插入一个度符号。代码如下。谢谢。

from numpy import *
import numpy as np
import matplotlib.pyplot as plt

theta1 = linspace(0,60,610)
theta2 = linspace(0,45,460)
theta3 = linspace(45,90,460)

CTS = 1/cos(radians(theta1))
CTS0 = 1/cos(radians(60-theta2))
CTS45 = 1/cos(radians(105-theta3))

plt.plot(theta1,CTS,label=u'CTS Head at 0',linewidth=2)
plt.plot(theta2,CTS0,label='CTS Head at 60',linewidth=2)
plt.plot(theta3,CTS45,label='CTS Head at 105',linewidth=2)

plt.xlabel('Manufactured Ply Angle (degrees)')
plt.ylabel('Thickness')

plt.legend( loc='lower right', numpoints = 1 )
plt.ylim([0,2.5])

plt.grid(b=None, which='major', axis='both')
plt.grid(color='k', linestyle='--', linewidth=0.5)
plt.axhline(y=1.035, xmin=0, xmax=90,color='k', linestyle='-', linewidth=1)

plt.show()

Tags: importnumpyplotpltcosheadlabelat
2条回答

使用乳胶数学。 在我的系统中,最好的视觉效果是

label = r'$45\degree$'

它看起来完全像极坐标图的默认θ标签。

正如其他人指出的那样

  • label = r'$45^\circ$'
  • label = '$45^o$'

等也可以,但视觉效果不太好。 在我的系统中,这些解决方案呈现的符号稍微太小。 YMMV,因此人们可能想尝试一下她系统中最漂亮的东西。

例如在半径为天顶角正弦的极坐标图上 一个人可能想用

deg_labels = np.array([5, 10, 20, 30, 45, 60, 90])
ax.set_rgrids(np.sin(np.deg2rad(deg_labels)),     
              labels=(r"${:.0f}\degree$".format(_) for _ in deg_labels))

使用乳胶风格。例如:$^\circ$ Text将产生°Text

有关打印(特别是数学表达式)的详细信息,请参见matplotlib documentation

在您的情况下,代码必须是:plt.xlabel('Manufactured Ply Angle $^\circ$')

表达式的TeX部分必须用美元符号“$”括起来。

相关问题 更多 >

    热门问题