0

I was trying to delete "y" axis in a figure, and I did. But when I plot the figure, I find that in the y axis there was a little line (' - '), so I don't know how to delete it.

I want to remove (-)'grid line' in the y axis, but i want to keep the ytick label. Is there a trick to do that?

I used this code:

plt.figure(figsize=(10,15))
plt.rcParams['axes.spines.right'] = False
plt.rcParams['axes.spines.top'] = False
plt.rcParams['axes.spines.left'] = False

plt.subplot(3,1,1)


axes=campos_entre_100.iloc[:,0][::-1].plot(kind="barh",stacked=True)
ylab = plt.ylabel("ESPOL",size=19.5,color='black',rotation=0, labelpad = 140)
ylab.set_position ((-120, 0.45))
plt.tick_params(axis='y', which='major', pad=22,labelsize=20)
plt.tick_params(axis='x', which='major', pad=10,labelsize=20)
plt.gca().xaxis.grid(True,linewidth=0.41)
valor3= campos_entre_100.iloc[:,0].values
pos= np.arange(0,len(valor3))[::-1]
for id, v_1 in enumerate(valor3):
    if v_1 >=0:
        plt.text(v_1+5 , pos[id] , str(v_1).replace('.',',') , ha="center", va="center", color="black", fontsize=16)
    elif v_1 <0:
        plt.text(v_1-7 , pos[id] , str(v_1).replace('.',',') , ha="center", va="center", color="black", fontsize=16)


plt.subplot(3,1,2)

campos_entre_100.iloc[:,1][::-1].plot(kind="barh",stacked=True)
ylab = plt.ylabel("Guayaquil",size=19.5,color='black',rotation=0, labelpad = 140)
ylab.set_position ((-100, 0.45))
plt.tick_params(axis='y', which='major', pad=22,labelsize=20)
plt.tick_params(axis='x', which='major', pad=10,labelsize=20)
plt.gca().xaxis.grid(True,linewidth=0.41)
valor3= campos_entre_100.iloc[:,1].values
pos= np.arange(0,len(valor3))[::-1]
for id, v_1 in enumerate(valor3):
    if v_1 >=0:
        plt.text(v_1+5 , pos[id] , str(v_1).replace('.',',') , ha="center", va="center", color="black", fontsize=16)
    elif v_1 <0:
        plt.text(v_1-5.4 , pos[id] , str(v_1).replace('.',',') , ha="center", va="center", color="black", fontsize=16)


plt.subplot(3,1,3)

at=campos_entre_100.iloc[:,2][::-1].plot(kind="barh",stacked=True)
ylab = plt.ylabel("Litoral",size=19.5,color='black',rotation=0, labelpad = 140)
ylab.set_position ((-100, 0.45))
plt.tick_params(axis='y', which='major', pad=22,labelsize=20)
plt.tick_params(axis='x', which='major', pad=10,labelsize=20)
plt.gca().xaxis.grid(True,linewidth=0.41)
valor3= campos_entre_100.iloc[:,2].values
pos= np.arange(0,len(valor3))[::-1]
for id, v_1 in enumerate(valor3):
    if v_1 >=0:
        plt.text(v_1+2 , pos[id] ,str( v_1).replace('.',',') , ha="center", va="center", color="black", fontsize=16)
    elif v_1 <0:
        plt.text(v_1-2.5 , pos[id] ,str( v_1).replace('.',',') , ha="center", va="center", color="black", fontsize=16)


plt.show()

And the result was this:

enter image description here

  • You've removed the y axis spine, but the y axis ticks are still there. You need to remove them too – DavidG May 05 '20 at 15:38
  • Have you looked at [this](https://stackoverflow.com/questions/2176424/hiding-axis-text-in-matplotlib-plots)? – arpitrathi May 05 '20 at 15:44

1 Answers1

0

To turn the Y axis off, try this:

ax1 = plt.axes()
ax1.axes.get_yaxis().set_visible(False)

It should get rid of everything, even the 'ticks'.

ClemPat
  • 49
  • 8