python - Seaborn,更改颜色栏的字体大小

标签 python matplotlib seaborn

我想更改热图颜色栏的字体大小。

以下是我的代码:

import seaborn as sns
import matplotlib.pyplot as plt
from numpy import arange
x = arange(25).reshape(5, 5)
cmap = sns.diverging_palette(220, 20, sep=20, as_cmap=True)
ax = sns.heatmap(x, cmap=cmap)
plt.show()

我能够使用 plt.tick_params(axis='both', labelsize=20) 更改刻度标签。但是,颜色条字体大小不会改变。 有办法吗?

enter image description here

最佳答案

您可以使用 matplotlib.axes.Axes.tick_params带有标签大小。

例如,标签大小为 20 的绘图:

import seaborn as sns
import matplotlib.pyplot as plt
from numpy import arange
x = arange(25).reshape(5, 5)
cmap = sns.diverging_palette(220, 20, sep=20, as_cmap=True)
ax = sns.heatmap(x, cmap=cmap)
# use matplotlib.colorbar.Colorbar object
cbar = ax.collections[0].colorbar
# here set the labelsize by 20
cbar.ax.tick_params(labelsize=20)
plt.show()

enter image description here

我引用了下面的回答:
- Using matplotlib.colorbar.Colorbar object
- Setting parameter

关于python - Seaborn,更改颜色栏的字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37233108/

相关文章:

python - 如何将日期时间格式的排列转换为在Python中绘制?

python - 使用可变行号矩阵注释 matplotlib 图形

python - 在 Seaborn Jointplot 上注释异常值

python - 为什么我在 seaborn 线图中得到线影?

python - Celery 忽略 retry_backoff,而是重复重试 180 秒

python - 在 RedShift 中使用 Django 多数据库

python - 使用 matplotlib 中的数据框绘制 3D 图

python - 如何在 seaborn fiddle 情节中为每个组分配不同的位置

Python 引用计数和 ctypes

python - Python 的 pip 是否有像 npm/package.json 这样的项目文件支持?