Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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轴的子地块添加x标签?_Python_Matplotlib_Plot_Subplot - Fatal编程技术网

Python 如何向跨越整个x轴的子地块添加x标签?

Python 如何向跨越整个x轴的子地块添加x标签?,python,matplotlib,plot,subplot,Python,Matplotlib,Plot,Subplot,如何添加跨越2个子批次的X标签?第二,如何使用子批次b/c xticks或SETxticklabels调整X轴索引似乎无法正确显示?如果有帮助,我可以提供数据集。我认为我正确地使用了subplot命令 x1 = np.r_[50:64] x2 = np.r_[89:103] fig, (ax1, ax2) = plt.subplots(1, 2, sharey=True) #Left plot ax1.plot(x1,left[0],color='red',marker="o",label=r

如何添加跨越2个子批次的X标签?第二,如何使用子批次b/c xticks或SETxticklabels调整X轴索引似乎无法正确显示?如果有帮助,我可以提供数据集。我认为我正确地使用了subplot命令

x1 = np.r_[50:64]
x2 = np.r_[89:103]
fig, (ax1, ax2) = plt.subplots(1, 2, sharey=True)

#Left plot
ax1.plot(x1,left[0],color='red',marker="o",label=r'$\alpha$PV Ca$^{2+}$',linestyle='dashed',markersize=6)
ax1.plot(x1,left[1],color='blue',marker="o",label=r'$\alpha$PV Mg$^{2+}$',linestyle='dashed',markersize=6)
ax1.plot(x1,left[2],color='red',marker="o",label=r'$\alpha$PV S55D/E59D Ca$^{2+}$',linestyle='solid',linewidth='6',markersize=10)
ax1.plot(x1,left[3],color='blue',marker="o",label=r'$\alpha$PV S55D/E59D Mg$^{2+}$',linestyle='solid',linewidth='6',markersize=10)
ax1.plot(x1,left[4],color='red',marker="o",label=r'$\alpha$PV D94S/G98E Ca$^{2+}$',linestyle='solid',linewidth='1',markersize=6)
ax1.plot(x1,left[5],color='blue',marker="o",label=r'$\alpha$PV D94S/G98E Mg$^{2+}$',linestyle='solid',linewidth='1',markersize=6)
#Right plot
ax2.plot(x2,right[0],color='red',marker="o",label=r'$\alpha$PV Ca$^{2+}$',linestyle='dashed',markersize=6)
ax2.plot(x2,right[1],color='blue',marker="o",label=r'$\alpha$PV Mg$^{2+}$',linestyle='dashed',markersize=6)
ax2.plot(x2,right[2],color='red',marker="o",label=r'$\alpha$PV S55D/E59D Ca$^{2+}$',linestyle='solid',linewidth='6',markersize=10)
ax2.plot(x2,right[3],color='blue',marker="o",label=r'$\alpha$PV S55D/E59D Mg$^{2+}$',linestyle='solid',linewidth='6',markersize=10)
ax2.plot(x2,right[4],color='red',marker="o",label=r'$\alpha$PV D94S/G98E Ca$^{2+}$',linestyle='solid',linewidth='1',markersize=6)
ax2.plot(x2,right[5],color='blue',marker="o",label=r'$\alpha$PV D94S/G98E Mg$^{2+}$',linestyle='solid',linewidth='1',markersize=6)


ax1.legend(fontsize=14,handlelength=2,loc="best")
ax1.set_ylabel('Contribution Energy (kcal/mol)', fontsize=25)
ax1.tick_params(axis='both', which='major', labelsize=28, length=9, width=4)
ax2.tick_params(axis='x', which='major', labelsize=28, length=9, width=4)
plt.tight_layout()
plt.suptitle('\u03B1PV WT and Mutants',fontsize=35)
plt.subplots_adjust(top=.90)


设置xlabel时可以使用x参数。以下是一个例子:

gs = gridspec.GridSpec(1,2)
fig = plt.figure(figsize=(10, 5))
ax = fig.add_subplot(gs[:, 0])
ax2 = fig.add_subplot(gs[:, 1])
data = [1,2,3,4,5]
ax.plot(data,data)
ax2.plot(data,data)
ax.set_xlabel("xLabelAcrossTwoSubPlot",x=1.1,fontsize=20)

此外,如果要明确控制滴答声,请参见以下方法:

### control ticks
ts = data[:]
ax.set_xticks(ts)
ax.set_xticklabels([ '#%d'%k for k in ts])