Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何设置双x轴标签?_Python_Matplotlib_Plot_Label - Fatal编程技术网

Python 如何设置双x轴标签?

Python 如何设置双x轴标签?,python,matplotlib,plot,label,Python,Matplotlib,Plot,Label,我就在这里: 我想把它改成这样: 代码如下所示: D_max_ratio=numpy.divide(D_max_Nobs,D_max_1000) fig = plt.figure() plt.set_cmap('jet_r') x_axis = ['100', '', '300', '',"500","","700","","900","","1100","","1300","","1500"] y_axis = ['10', '20', '30', '40',"50","60","70"

我就在这里:

我想把它改成这样:

代码如下所示:

D_max_ratio=numpy.divide(D_max_Nobs,D_max_1000)
fig = plt.figure()
plt.set_cmap('jet_r')
x_axis = ['100', '', '300',  '',"500","","700","","900","","1100","","1300","","1500"]
y_axis = ['10', '20', '30', '40',"50","60","70","80","90","100"]
ax = fig.add_subplot(111)
cax = ax.matshow(D_max_ratio)
ax.xaxis.set_ticks_position('bottom')
ax.set_xticks(numpy.arange(15))
ax.set_yticks(numpy.arange(10))
ax.set_xticklabels(x_axis)
ax.set_yticklabels(y_axis)
plt.xlabel('f/MHz')
plt.ylabel('$N_{obs}^{R}$')
cb=fig.colorbar(cax)

你要的是一个寄生虫轴,如图所示,在你的病例中

from mpl_toolkits.axes_grid1 import host_subplot
import mpl_toolkits.axisartist as AA
import matplotlib.pyplot as plt
import numpy as np

#Setup a host axis
host = host_subplot(111, axes_class=AA.Axes)
plt.subplots_adjust(bottom=0.2)

#Add twin y axis with offset from bottom and hide top axis
par = host.twiny()
offset = -30
new_fixed_axis = host.get_grid_helper().new_fixed_axis
par.axis["bottom"] = new_fixed_axis(loc="bottom",
                                    axes=par,
                                    offset=(0, offset))
par.axis["top"].set_visible(False)

# Plot data and add main axis labels/limits
host.imshow(np.random.rand(128,1600))
host.set_xlabel("f/MHz")
host.set_xlim((0,1600))
plt.axis("tight")

#Set limits of parasite axis 
#(note this axis is not attached to 
# an actual plot so changes nothing)

par.set_xlabel("Ka")
par.set_xlim((0,15.71))

plt.draw()
plt.show()
看起来


不这样做怎么样?结果将使读者感到困惑。用
twiny
功能创建第二个x轴。我是助理,这是主管的要求。所以~~所以我觉得没有这么容易使用的功能
imshow
可以通过一些技巧帮助您实现目标。谢谢,这正是我需要的。另外,我可以删除顶部的轴吗?嗨@Tang,我昨天没法解决这个问题(你需要调用
par.axis[“top”]。设置为可见(False)
),有点匆忙。更新以删除顶轴,并使其更像您的案例。