简体   繁体   English

在matplotlib中删除x轴共享图中的多余行情

[英]remove redundant ticker in x-axis shared plot in matplotlib

I just tried to draw a x-axis shared plot. 我只是试图绘制一个x轴共享图。 But there is a redundant axis (0 and 1 on the edge of the plot)in the y axis. 但是y轴上有一个冗余轴(图的边缘为0和1)。 How can I get rid of this? 我该如何摆脱呢?

import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
plt.figure()
gs1 = gridspec.GridSpec(8, 4)
gs1.update(left=0.05, right=0.65, hspace=0)
axF = plt.subplot(gs1[0, :])
axE = plt.subplot(gs1[1, :],sharex=axF)
axPA = plt.subplot(gs1[2, :],sharex=axF)
axMiu = plt.subplot(gs1[3:7, :],sharex=axF)
axRes = plt.subplot(gs1[7, :],sharex=axF)

Sorry that I'm not able to post the image. 抱歉,我无法发布图片。 As you can see on the result image, there are some overlapped or redundant axis values on the left or right of y axis. 如您在结果图像上看到的,y轴的左侧或右侧有些重叠或冗余的轴值。 Thanks in advance! 提前致谢!

You can use the yaxis.set_ticks function to define what ticks you want 您可以使用yaxis.set_ticks函数定义所需的刻度

For example : 例如 :

import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import numpy as np

plt.figure()
gs1 = gridspec.GridSpec(8, 4)
gs1.update(left=0.05, right=0.65, hspace=0)

plot=[]

axF = plt.subplot(gs1[0, :])
plot.append(axF)

axE = plt.subplot(gs1[1, :],sharex=axF)
plot.append(axE)

axPA = plt.subplot(gs1[2, :],sharex=axF)
plot.append(axPA)

axMiu = plt.subplot(gs1[3:7, :],sharex=axF)
plot.append(axMiu)

axRes = plt.subplot(gs1[7, :],sharex=axF)
plot.append(axRes)

for plot_selected in plot:
    plot_selected.yaxis.set_ticks(np.arange(0.2,1.1,0.2))
    plot_selected.xaxis.set_ticks(np.arange(0.2,1.1,0.2))

plot_selected.yaxis.set_ticks(np.arange(0,1.1,0.2))



plt.show()

Gives the following plot : 给出以下情节:

plot_example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM