如何在seaborn.heatmap图中将yticks和xticks居中?

时间:2019-07-16 00:59:13

标签: python matplotlib seaborn

我有这些图,它们代表了我正在研究的数据集中的一些混淆矩阵。但是当我绘制图形时,它并没有保持应有的对齐状态。

    def save_graph_cm(CMatrix):
        # Cmatrix is a pandas DataFrame with size NxN with index/columns labeled from 1 to n
        fig = plt.figure()
        plt.suptitle("Some title")
        cm = 1
        for c_matrix in CMatrix.keys():
            plot = fig.add_subplot(2, 2, cm)
            sn.heatmap(CMatrix[c_matrix], annot=True, cmap="YlOrRd", square=True)
            plt.yticks()
            plot.set_title("CV - " + str(cm - 1), fontsize=10)
            plot.set_xlabel("x_label")
            plot.set_ylabel("y_label")
            cm += 1
        fig.subplots_adjust(hspace=.5, wspace=0.5)
        plt.show()

Here's the output i'm getting now

Here's an example of how it should be, but the example is showing only one matrix

一些其他信息:

seaborn==0.9.0
matplotlib==3.1.1
pandas==0.24.2

0 个答案:

没有答案