为什么matplotlib标签的'fontsize'不起作用?

7
我使用了下面的函数,但标签大小没有改变。
axe.set_xlabel('$R^{-1}_m$ (nm$^{-1}$)')
axe.xaxis.label.set_size(18)
axe.set_ylabel('$E_{f}/l_{z}$ (eV/nm)',fontsize=40)
axd.set_xlabel(r"$D$ (nm)",color='blue',fontsize=28)

我没有足够的声望发布图片。所以我在这里发布它:http://imgur.com/T2pbd9B

三个标签的大小不会改变,无论'fontsize'标签设置多大。

原始代码如下:

from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import host_subplot
import mpl_toolkits.axisartist as AA
from matplotlib.patches import Rectangle

colormap = {'0':'yellow','1':'Indigo','2':'pink','3':'blue','4':'magenta','5':'orange','6':'cyan','7':'chartreuse','8':'royalblue','9':'red','10':'navy',}
markershape={'0':'o','1':vec1,'2':rotate_vec(vec2),'3':'^','4':'s','5':'p','6':'H','7':(7,0,0),'8':'8','9':(9,0,0),'10':(10,0,90),}
mksz=12
markersizemap={'0':mksz,'1':mksz*1.1,'2':mksz*1.1,'3':mksz*0.9,'4':mksz*0.8,'5':mksz,'6':mksz,'7':mksz,'8':mksz*1.1,'9':mksz*1.2,'10':mksz*1.2,}   
fitxx = np.arange(4)    
e_xmin=0.8;e_xmax=2.1;e_ymin=20;e_ymax=38

fig=plt.figure(num=None, figsize=(8,6), dpi=110, facecolor='w', edgecolor='k') 
ax0 = host_subplot(111, axes_class=AA.Axes)
rec=Rectangle((e_xmin,e_ymin), e_xmax-e_xmin, e_ymax-e_ymin, ec="w",fc='lightgrey',alpha=0.4)
ax0.add_patch(rec)
for nn in range(len(lstall)):
    fityy=aaa(nn)*fitxx+bbb(nn)
    ax0.plot(fitxx,fityy,'--',color=colormap['%d'%nn],linewidth=2)
    ax0.plot(lstall[nn][:,0],lstall[nn][:,1],marker=markershape['%d'%nn],markersize=markersizemap['%d'%nn],color=colormap['%d'%nn],label="n={}".format(nn),linestyle='None')
ax0.set_xlabel(r'$R^{-1}_m$ (nm$^{-1}$)')
ax0.xaxis.label.set_size(18)
ax0.set_ylabel(r'$E_{f}/l_{z}$ (eV/nm)',fontsize=100)
xmax=2.1
ax0.set_xlim((0, xmax));ax0.set_ylim((0, 62));ax0.grid(False)
axd = ax0.twiny();axd.grid()
dticklabels =['9','7','6','5','4','3','2','1.5','1','%.2f'%(2/xmax)] 
def tick_function(X):
    V=[]
    for dd in X:
        kk = 2/float(dd)
        V.append(kk)       
    return V
curvticks=tick_function(dticklabels)
dticklabels.pop(-1)
dticklabels.append(' ')
axd.set_xticks(curvticks)
axd.set_xticklabels(dticklabels)
axd.set_xlabel(r"Diameter $D$ (nm)",color='blue',fontsize=28)
fig.savefig('%s/data1.png'%path,bbox_inches='tight')
fig.savefig('%s/data1.eps'%path,bbox_inches='tight')

1
您可以发布图像链接。另外,您能否提供演示您问题的最小但完整的工作代码。 - Marcin
@Marcin 你好。链接和部分完整的代码已添加。 - smirkymonkey
1个回答

14

你可以尝试

params = {'axes.labelsize': 18,'axes.titlesize':20, 'text.fontsize': 20, 'legend.fontsize': 20, 'xtick.labelsize': 28, 'ytick.labelsize': 40}
matplotlib.rcParams.update(params)

1
非常感谢!它起作用了!!很抱歉我没有足够的声望来点赞... 顺便问一下,为什么我的以前的代码不起作用呢? - smirkymonkey
我认为,在我的代码中使用了类似于这样的语句,axd.set_xlabel(r"$D$ (nm)",color='blue',fontsize=28),但它不一致,有时起作用,有时不起作用,因此我改用答案中提到的当前方法。 - Kirubaharan J
谢谢,这解决了我的问题。这一定与子图轴有关。 - arie64
我的问题也解决了,实际上很难找到这个答案。无论如何,谢谢你。 - Cherny

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接