在 Seaborn 中隐藏轴标题 [英] Hide Axis Titles in Seaborn

查看:32
本文介绍了在 Seaborn 中隐藏轴标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于以下热图,我将如何删除轴标题(月"和年")?

Given the following heatmap, how would I remove the axis titles ('month' and 'year')?

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)

推荐答案

在调用 sns.heatmap 之前,使用 plt.subplots 获取坐标轴,然后使用 set_xlabelset_ylabel.例如:

Before calling sns.heatmap, get the axes using plt.subplots, then use set_xlabel and set_ylabel. For example:

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('')

这篇关于在 Seaborn 中隐藏轴标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆