【发布时间】:2021-01-12 07:56:05
【问题描述】:
我正在尝试使用对数颜色条制作热图。但它会不断生成自己的刻度和刻度标签以及我输入的刻度。
我最初发布 this 是为了将刻度标签从科学记数法重新格式化为普通格式,但后来遇到了这个问题。
import numpy as np
import seaborn as sns
from matplotlib.colors import LogNorm
import matplotlib.ticker as tkr
matrix = np.random.rand(10, 10)/0.4
vmax=2
vmin=0.5
cbar_ticks = [0.5, 0.75, 1, 1.33, 2]
formatter = tkr.ScalarFormatter(useMathText=True)
formatter.set_scientific(False)
log_norm = LogNorm(vmin=vmin, vmax=vmax)
ax = sns.heatmap(matrix, square=True, vmax=vmax, vmin=vmin, norm=log_norm, cbar_kws={"ticks": cbar_ticks, "format": formatter})
【问题讨论】:
-
原来,这是 matplotlib 中的一个已知错误 github.com/matplotlib/matplotlib/issues/12503
标签: python matplotlib seaborn