我一直在尝试为xaxis找到正确的格式,半天没有成功。我希望xaxis刻度标签为(10 ^ -4,10 ^ -3,10 ^ -2,0.1,1,10),并且可能没有缩放(两个标签之间的距离相同或几乎相同)。请帮忙。到目前为止,我的代码如下所示。
import matplotlib.pyplot as plt;
import numpy as np;
from matplotlib import rc;
from matplotlib.ticker import ScalarFormatter;
filename = '../Data/to.pdf';
fig, ax1 = plt.subplots(frameon=False);
rc('mathtext', default='regular');
rc('font', family='serif');
rc('lines',lw=2.6);
rc('lines',mew=2.4);
#x = np.logspace(-4,1,num=6);
x = np.array([1e-4,1e-3,1e-2,1e-1,1,10]);
nd_5 = np.array([65.96, 65.93, 65.31, 58.94, 61.04, 57.79]);
nd_10 = np.array([79.70, 79.67, 79.20, 75.09, 76.77, 74.80]);
ld_5 = np.array([ 6.29, 6.32, 6.62, 7.17, 6.64, 6.66]);
ld_10 = np.array([ 6.65, 6.66, 6.76, 6.94, 6.66, 6.81]);
lns1 = ax1.plot(x,ndcg_5,'bs-',label='ND@5');
lns2 = ax1.plot(x,ndcg_10,'bv-',label='ND@10');
ax1.set_ylabel('ND (%)',color='b',size=14);
ax1.set_ylim([50,85]);
ax1.set_xlim([0.0005,10.5]);
ax1.set_xticks(x);
ax1.tick_params(axis='y', which=u'both', length=0, labelsize=14, colors='b');
ax1.tick_params(axis='x', which=u'both', length=0, labelsize=14);
ax1.ticklabel_format(style='sci', axis='x', scilimits=(-2,1),useOffset=False)
ax2 = ax1.twinx();
lns3 = ax2.plot(x,ild_5,'rs-',label='ILD@5');
lns4 = ax2.plot(x,ild_10,'rv-',label='ILD@10');
ax2.set_ylabel('LD',color='r',size=14);
ax2.set_ylim([5,9]);
#ax1.set_xlim([0.0005,10.5]);
ax2.set_xticks(x);
ax2.tick_params(axis='y', which=u'both', length=0, labelsize=14, colors='r');
ax2.tick_params(axis='x', which=u'both', length=0, labelsize=14);
ax2.ticklabel_format(style='sci', axis='x', scilimits=(-2,1),useOffset=False)
lns = lns1 + lns2 + lns3 + lns4 ;
labs = [l.get_label() for l in lns];
lgd = ax1.legend(lns, labs, bbox_to_anchor=(1.01,1.0), loc=0, borderaxespad=2.5, ncol = 1, fontsize='14');
fig.savefig(filename,format='pdf',transparent=True, bbox_extra_artists=(lgd,), bbox_inches='tight');