[英]Seaborn heatmap integer formatting
I have a heatmap plot with integers showing.我有一个显示整数的热图。 As the numbers are quite high I was wondering if it is possible to write k
instead of 000
?由于数字相当高,我想知道是否可以写k
而不是000
? So 417924
would become 418k
.所以417924
将变成418k
。
confusion_matrix = ([[417924, 67554],
[ 24901, 11070]])
x_axis_labels = ['predicted_non_churns','predicted_churns'] # labels for x-axis
y_axis_labels = ['actual_non_churns','actual_churns'] # labels for y-axis
ax = plt.axes()
ax.set_title('Confusion Matrix',fontsize=14, fontweight='bold')
sn.heatmap(confusion_matrix, annot=True, cmap="Purples",
xticklabels=x_axis_labels, yticklabels=y_axis_labels, fmt='g', ax=ax) # font size
Thanks a lot非常感谢
You can define your own annotation with the annot
parameter.您可以使用annot
参数定义自己的注释。 Create a separate array with 'k'
and apply it to your heatmap.使用'k'
创建一个单独的数组并将其应用于您的热图。 You'll need to set fmt
to ''
as well:您还需要将fmt
设置为''
:
rnd = np.round(confusion_matrix/1000).astype(int)
annot = np.char.add(rnd.astype(str), 'k')
sns.heatmap(confusion_matrix, annot=annot, fmt='', cmap="Purples",
xticklabels=x_axis_labels, yticklabels=y_axis_labels, ax=ax)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.