2015-12-14 84 views
6

鑑於以下熱圖,我將如何刪除軸標題(「月」和「年」)?在Seaborn中隱藏軸標題

import seaborn as sns 

# Load the example flights dataset and conver to long-form 
flights_long = sns.load_dataset("flights") 
flights = flights_long.pivot("month", "year", "passengers") 

# Draw a heatmap with the numeric values in each cell 
sns.heatmap(flights, annot=True, fmt="d", linewidths=.5) 

current graph

回答

10

在致電sns.heatmap,讓使用plt.subplots軸,然後使用set_xlabelset_ylabel。例如:

import seaborn as sns 
import matplotlib.pyplot as plt 

# Load the example flights dataset and conver to long-form 
flights_long = sns.load_dataset("flights") 
flights = flights_long.pivot("month", "year", "passengers") 

# ADDED: Extract axes. 
fig, ax = plt.subplots(1, 1, figsize = (15, 15), dpi=300) 

# Draw a heatmap with the numeric values in each cell 
sns.heatmap(flights, annot=True, fmt="d", linewidths=.5) 

# ADDED: Remove labels. 
ax.set_ylabel('')  
ax.set_xlabel('') 

New graph