python matplotlib绘图时如何在图上显示希腊字母alpha

代码如下:

plt.xlabel(r'$\alpha$', font2)

完整例子:

import matplotlib.pyplot as plt

from matplotlib.pyplot import MultipleLocator

plt.style.use("seaborn-darkgrid")

labels = [0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]

a0 = [0.9717,0.9640,0.9553,0.9568,0.9589,0.9724,0.9752,0.9733,0.9678,0.9596,0.9511]

b0 = [0.9927,0.9927,0.9908,0.9899,0.9927,0.9951,0.9908,0.9908,0.9890,0.9862,0.9773]

c0 = [0.9939,0.9963,.9954,0.9945,0.9936,0.9954,0.9954,0.9963,0.9945,0.9908,0.9716]

#设置图例并且设置图例的字体及大小

font1 = {'family': 'Times New Roman', 'weight': 'normal', 'size': 10}

font2 = {'family': 'Times New Roman', 'weight': 'normal', 'size': 15}

plt.xticks(fontproperties = 'Times New Roman',fontsize=10)

plt.yticks(fontproperties = 'Times New Roman',fontsize=10)

fig = plt.figure(figsize=(6,4))

plt.plot(labels, a0, c='blue', marker='x', linestyle='-', label='10%')

plt.plot(labels, b0, c='y', marker='*', linestyle='-', label='20%')

plt.plot(labels, c0, c='m', marker='+', linestyle='-', label='40%')

# plt.xlabel(u'Label rate', font1)

plt.ylabel(u'Accuracy', font2)

plt.xlabel(r'$\alpha$', font2)

# 图例展示位置,数字代表第几象限

plt.legend(loc=0, prop=font1)

ax = plt.gca()

# ax.xaxis.set_major_locator(x_major_locator)

plt.show()

参考链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: