我正在使用子图绘制多个图。
我想删除除左侧之外的所有 yticks,以及除底部之外的所有 xticks。我正在尝试创建共享轴。
我尝试了一些 stackoverflow 答案,例如使用plt.tick_params和定位某些子图:
if num in [2,3,5,6,8,9] :
plt.tick_params(labelleft='off')
if num not in range(7) :
plt.tick_params(labelbottom='off')
我也尝试tick_params在最后进行调整:
plt.tick_params(axis='both', which='both', right=False, left=True, top=False, bottom=True)
然而,所有 yticks 和 xticks 每次都会出现。
我可以尝试另一种方法吗?
到目前为止我的绘图代码:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
sns.set_style("whitegrid")
myl = sns.color_palette().as_hex()
num=0
# figure size
plt.figure(figsize=(20, 30))
for column in newtempgraph.drop(['local_date'], axis=1):
num+=1
# Find the right spot on the plot
plt.subplot(7,3, num)
# Plot the lineplot
plt.plot(newtempgraph['local_date'], newtempgraph[column], color=myl[num-1], linewidth=1.9, alpha=0.9, label=column,linestyle='--')
# Same limits for everybody
plt.xlim(newtempgraph['local_date'].min(),newtempgraph['local_date'].max())
plt.ylim(0,1464)
# Not ticks everywhere
if num in [2,3,5,6,8,9] :
plt.tick_params(labelleft='off')
if num not in range(7) :
plt.tick_params(labelbottom='off')
# Add title
plt.title(column, loc='left', fontsize=20, fontweight=0, color=myl[num-1] )
plt.xticks(fontsize=13,rotation=45)
plt.yticks(fontsize=15)
plt.suptitle("Performance of Shops", fontsize=20, fontweight=0, color='black', style='italic', y=1.02)
plt.tick_params(axis='both', which='both', right=False, left=True, top=False, bottom=True)
plt.tight_layout()
#plt.tick_params(axis='both', which='both', right=False, left=True, top=False, bottom=True)
慕少森
相关分类