从一个子图中删除轴刻度

时间:2020-06-22 17:06:38

标签: python matplotlib

我只能从一个子图中删除轴标签。我尝试的所有内容都将其删除。我的目标是将刻度线保留在左侧,而将其删除在右侧。这是我尝试过的。

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

#some data.
x = np.arange(1,11)

fig = plt.figure(1)
grid = gridspec.GridSpec(1, 2)
grid.update(hspace=0)


plt0 = plt.subplot(grid[0,0])
plt.plot(x,x)

plt1 = plt.subplot(grid[0,1], sharey =plt0)
#The line below removes ticks from both subplots.
plt1.set_yticks([])
plt.plot(x,2*x)

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

您可以使用labelleft=False关闭对勾标签,并使用length=0隐藏对勾标记。

plt1.tick_params(labelleft=False, length=0)

plt.plot(x, 2*x)

enter image description here