Question

I'm trying to increase the values size in a colorbar. Seems trivial but I have not been able to figure it out.

I have produced a heatmap and here is the code:

def heatmap_binary(df,
            edgecolors='w',
            cmap=mpl.cm.seismic, # spectral, Blues, gist_rainbow, rainbow, hsv, seismic,
            log=False):    
    width = len(df.columns)/7*10
    height = len(df.index)/7*10

    fig, ax = plt.subplots(figsize=(20,60))#(figsize=(width,height))

    #cmap, norm = mcolors.from_levels_and_colors([0, 0.05, 1],['Teal', 'MidnightBlue'] ) # ['MidnightBlue', Teal]['Darkgreen', 'Darkred']

    heatmap = ax.pcolor(df ,
                        edgecolors=edgecolors,  # put white lines between squares in heatmap
                        cmap=cmap,
                        norm=mpl.colors.LogNorm() if log else None)
    data = df.values
    for y in range(data.shape[0]):
        for x in range(data.shape[1]):
            plt.text(x + 0.5 , y + 0.5, '%.4f' % data[y, x], #data[y,x] +0.05 , data[y,x] + 0.05
                 horizontalalignment='center',
                 verticalalignment='center',
                 color='w',size=30)


    ax.autoscale(tight=True)  # get rid of whitespace in margins of heatmap
    ax.set_aspect('equal')  # ensure heatmap cells are square
    ax.xaxis.set_ticks_position('top')  # put column labels at the top
    ax.tick_params(bottom='off', top='off', left='off', right='off')  # turn off ticks

    ax.set_yticks(np.arange(len(df.index)) + 0.5)
    ax.set_yticklabels(df.index, size=30)
    ax.set_xticks(np.arange(len(df.columns)) + 0.5)
    ax.set_xticklabels(df.columns, size= 20)


    from mpl_toolkits.axes_grid1 import make_axes_locatable
    divider = make_axes_locatable(ax)
    cax = divider.append_axes("right", "3%", pad="1%")
    cbar = fig.colorbar(heatmap, cax=cax)
    cbar.ax.set_ylabel('Difference', fontsize=30) 

Output from function call:

heatmap_binary(dataframe)

enter image description here

Aany tips?

Was it helpful?

Solution

use tick_params():

cax.tick_params(labelsize=20)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top