[英]How can axes be despined in Matplotlib?
我試圖使下面的圖表網格更清晰一點。 我不希望左側和底部的刻度線重疊。 我試圖通過嘗試下面的代碼來消除軸,但它似乎不起作用。 有人有什么建議嗎?
fig, ax = plt.subplots(figsize=(15,10))
cols = ['x6', 'x7', 'x16', 'x17']
subset = df[cols]
normed_df = (subset-subset.min())/(subset.max()-subset.min())
style.use('seaborn-darkgrid')
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['bottom'].set_visible(False)
for sp in range(4):
ax = fig.add_subplot(2,2, sp+1)
ax.hist(normed_df[cols[sp]], density=True)
normed_df[cols[sp]].plot.kde(ax=ax)
ax.tick_params(bottom="off", top="off", left="off", right="off")
當您在不指定網格的情況下調用plt.subplots()
,它會在整個圖形中創建那些軸,其刻度線和標簽會干擾最終圖中的子圖刻度標簽。 因此,將您的第一行代碼更改為:
fig, ax = plt.subplots(2, 2, figsize=(15,10))
要么做@Arne建議的事情:
fig, ax = plt.subplots(rows, cols) #makes a grid of subplots
或者讓你的前兩行這樣:
fig, ax = plt.subplots(figsize=(15,10))
ax.axis('off')
這將在添加其他子圖之前刪除整個子圖周圍的軸
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.