Python 在对数刻度上放置标签

Python 在对数刻度上放置标签,python,matplotlib,axis-labels,Python,Matplotlib,Axis Labels,我有一个带有插图的绘图,我在设置记号位置和标签的位置时遇到问题 我有一个带插图的图,我有插图的问题。我的插图代码如下所示: import matplotlib.pyplot as plt fontsmall=16 left, bottom, width, height = [.14, 0.70, 0.16, 0.20] ax3 = fig.add_axes([left, bottom, width, height]) plt.yscale('log') plt.xscale('log')

我有一个带有插图的绘图,我在设置记号位置和标签的位置时遇到问题

我有一个带插图的图,我有插图的问题。我的插图代码如下所示:

import matplotlib.pyplot as plt 
fontsmall=16
left, bottom, width, height = [.14, 0.70, 0.16, 0.20]
ax3 = fig.add_axes([left, bottom, width, height])
plt.yscale('log')
plt.xscale('log')


ax3.set_xlim(0.6,10)
ax3.set_ylim(1,1*10**3)

xaxis=[1,10]
yaxis=np.power(xaxis,2.5)
ax3.plot(xaxis,yaxis,lw=2,color='black')

ax3.tick_params(labelleft='off',labelright='on')
ax3.yaxis.set_label_position("right")
ax3.tick_params(axis="x", pad=-0.5)
ax3.tick_params(axis='y',which='minor',left='off',right='off')
ax3.tick_params(axis='y',which='major',left='on',right='on')
ax3.set_ylabel('$K\'_0$ (Pa)',fontsize=fontsmall,rotation=270)
ax3.yaxis.labelpad = 19
ax3.xaxis.labelpad = -9
ax3.set_xlabel('$c_p$ (mg/ml)',fontsize=fontsmall)

#I want to have ticks at these positions:
ax3.yaxis.set_ticks((10**0,10**1,10**2,10**3))

#But the labels I want at position 10**1 and 10**3, in log format

#trying to remove 10**0 and 10**2, but this makes the labels in 10, and 1000 instead of the log format
#labels = [item.get_text() for item in ax3.get_yticklabels()] 
#labels[0] = ''
#labels[2] = ''
#
#ax3.set_yticklabels(labels)

#other method I came across:
a=ax3.get_yticks().tolist()
a[0]=''
a[2]=''
ax3.set_yticklabels(a)
#again, 10 and 1000 instead of the log format, when trying to change this:
ax3.yaxis.set_major_formatter(matplotlib.ticker.LogFormatter())
#now all 4 labels are visible again for some reason, and not in the 10^0  format I want
#
#
我看过多篇想改变记号和标签位置的文章。然而,我还没有遇到一篇文章既改变了标签的位置,又将其更改为我想要的正确日志格式。我怎么能这样做

或者,我也看到了一篇文章,他们将标签放在“隐形”上:

for label in ax3.get_yticklabels():
    label.set_visible(False)

但这会删除所有标签,这也不是我想要的。有没有办法只选择要删除的标签?

您非常接近,只需关闭两个特定标签的可见性,而不是所有标签。因此,不要使用for循环,只需像处理文本一样显式地执行它

labels = ax3.get_yticklabels()
labels[0].set_visible(False)
labels[2].set_visible(False)