Как увеличить размер ячейки для аннотации в Seaborn heatmap - PullRequest
0 голосов
/ 03 июля 2018

Я бы хотел построить 66x66 матрицу путаницы с min=0 и max=15075 (общая здесь ). Поскольку я хотел бы комментировать ячейки, я использую annot=True. Но я не могу вписать значения в ячейку даже после попытки подходов, предложенных в других сообщениях о переполнении стека, таких как this , this и this . Это мой текущий код:

from sklearn.metrics import confusion_matrix
conf_mat = confusion_matrix(y_test, y_pred) # please load the data from the pastebin [link above][1]

# get the tick label font size
fontsize_pt = 10 # plt.rcParams['ytick.labelsize'] does not return a numeric value like suggested [here][2], so I set it to '10'
dpi = 72.27

# comput the matrix height in points and inches
matrix_height_pt = fontsize_pt * conf_mat.shape[0]
matrix_height_in = matrix_height_pt / dpi

# compute the required figure height 
top_margin = 0.04
bottom_margin = 0.04
figure_height = matrix_height_in / (1 - top_margin - bottom_margin)

# build the figure instance with the desired height
fig, ax = plt.subplots(figsize=(20, figure_height),
                       gridspec_kw=dict(top=(1-top_margin), bottom=bottom_margin))

# here, I turned on annot and changed the color map scheme
ax = sns.heatmap(conf_mat, ax=ax, annot=True, cmap="cubehelix")

Когда я запускаю приведенный выше код, он возвращает фигуру, которая выглядит следующим образом

enter image description here

Мне бы хотелось, чтобы аннотированные фигуры помещались в каждой ячейке тепловой карты, и, если возможно, цветовой диапазон был бы более разумным (вместо того, чтобы быть черным, как сейчас).

Будем весьма благодарны за любые предложения по улучшению. Спасибо.

...