python-3.x - 在 Seaborn 中隐藏轴标题

标签 python-3.x 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

最佳答案

调用前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

关于python-3.x - 在 Seaborn 中隐藏轴标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34275140/

相关文章:

python - Vim 中的 Google Pytype

python - 从普通函数调用生成器函数

python - 使用 Python 在同一图中绘制两个猫图

python - 为 3D 体积绘制 seaborn 热图动画时出错

python - 使用 seaborn 绘图时如何处理缺失值?

python - 为什么使用 Seaborn 绘制回归时截距显示不正确?

python - 在 Seaborn PairGrid 中使用 lmplot

python - 尝试使用 BeautifulSoup 访问 XML 中的嵌套元素

python - 从 Python 执行 ffmpeg

unicode - Python 3 CGI : how to output raw bytes