[Python] Center colorbar Labels on Heatmap

Discussão em 'Python' iniciado por Stack, Outubro 24, 2024.

  1. Stack

    Stack Membro Participativo

    I have seen a few similar questions to this but haven't been able to make it work so I figured I would ask here.

    I have a seaborn heatmap with 2 overlaid scatter plots. When it plots the colorbar the labels aren't centered on the colors. I was wondering how to center the values on the colors. Also is it possible to always set the 0 color as white? My code and plot is below

    fig, ax = plt.subplots(figsize=(20, 20))

    plt.gca().set_aspect(RI/SI)
    cbar_kws=dict(pad=0.01,shrink=0.86, drawedges=True, ticks=range(int(maxfold)+1)) #Colorbar size and location

    cmap = plt.get_cmap('jet', maxfold+1)

    sns.heatmap(binspivot, cmap=cmap,linewidths=0.01, linecolor = 'black', vmin=0, vmax=maxfold, xticklabels=False, yticklabels=False,annot=True, annot_kws={"size": 20,"color":"black"},cbar_kws=cbar_kws)
    ax.set(xlabel=None, ylabel=None)
    ax.scatter(Sourcedfcut['Xmod'],Sourcedfcut['Ymod'], color="red", s = 400)
    ax.scatter(Recdfcut['Xmod'],Recdfcut['Ymod'], color="blue", s= 400)


    [​IMG]

    Continue reading...

Compartilhe esta Página