Reputation: 691
I'm attempting to hide the y-axis labels on a matplotlib axis. There seems to be an error that some of the labels are hidden but others are not. Is this a bug and is there a way to turn off all the labels? Is it the way that I'm plotting?
Note: I'm only showing half my plot the other half is a cartopy map.
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.io.img_tiles import Stamen
import cartopy.io.shapereader as shpreader
from cartopy.feature import ShapelyFeature
import os
import pickle
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point
from pathlib import Path
fig=plt.figure(figsize=(16,9), dpi=300, constrained_layout=True)
gs0=fig.add_gridspec(1,2)
gs00=gs0[0].subgridspec(10,1)
gs01=gs0[1].subgridspec(1,1)
data_dir='/data/files/'
ext_=f'*.pkl'
p=Path(data_dir).glob(ext_)
s=[str(i) for i in p]
for i,j in enumerate(s):
ax=fig.add_subplot(gs00[i,0])
f=pickle.load(open(j, 'rb'))
ax.loglog(f[0], f[2])
ax.margins(x=0)
ax.set_yticklabels([])
ax2=fig.add_subplot(gs01[0,0], projection=ccrs.PlateCarree())
Upvotes: 1
Views: 133
Reputation: 68
I think you can use plt.tick_params()
See explainations from this topic Remove xticks in a matplotlib plot?
Modification for y-axis:
from matplotlib import pyplot as plt
plt.plot(range(10))
plt.tick_params(
axis='y', # changes apply to the y-axis
which='both', # both major and minor ticks are affected
left=False, # ticks along the left edge are off
labelleft=False) # labels along the left edge are off
plt.show()
Upvotes: 1