Adjust space between tick labels a in matplotlib
Question: I based my heatmap off of: [Heatmap in matplotlib with
pcolor?](http://stackoverflow.com/questions/14391959/heatmap-in-matplotlib-
with-pcolor)

I checked out [How to change separation between tick labels and axis labels in
Matplotlib](http://stackoverflow.com/questions/21539018/how-to-change-
separation-between-tick-labels-and-axis-labels-in-matplotlib) but it wasn't
what I needed

[![enter image description
here](http://i.stack.imgur.com/ltqNl.png)](http://i.stack.imgur.com/ltqNl.png)

**How do I fix the positions of the labels so they align with the ticks?**

    
    
    #!/usr/bin/python
    
    import matplotlib.pyplot as plt
    import numpy as np
    import random
    in_path = '/path/to/data'
    in_file = open(in_path,'r').read().split('\r')
    wd = '/'.join(in_path.split('/')[:-1]) + '/'
    column_labels = [str(random.random()) + '_dsiu' for i in in_file[0].split('\t')[2:]]
    row_labels = []
    
    
    #Organize data for matrix population
    D_cyano_counts = {}
    for line in in_file[2:]:
        t = line.split('\t')
        D_cyano_counts[(t[0],t[1])] = [int(x) for x in t[2:]]
    
    
    #Populate matrix
    matrix = []
    for entry in sorted(D_cyano_counts.items(), key = lambda x: (np.mean([int(bool(y)) for y in x[-1]]), np.mean(x[-1]))):#, np.mean(x[-1]))):
        (taxon_id,cyano), counts = entry
        normalized_counts = []
        for i,j in zip([int(bool(y)) for y in counts], counts):
            if i > 0:
                normalized_counts.append(i * (5  + np.log(j)))
            else:
                normalized_counts.append(0)
    
        #Labels
        label_type = 'species'
        if label_type == 'species': label = cyano
        if label_type == 'taxon_id': label = taxon_id
        row_labels.append(str(random.random()))
    
        #Fill in matrix
        matrix.append(normalized_counts)
    matrix = np.array(matrix)
    
    #Fig
    fig, ax = plt.subplots()
    heatmap = ax.pcolor(matrix, cmap=plt.cm.Greens, alpha = 0.7)
    #Format
    fig = plt.gcf()
    #
    ax.set_frame_on(False)
    #
    font = {'size':3}
    ax.xaxis.tick_top()
    ax.set_xticks([i + 0.5 for i in range(len(column_labels))])
    ax.set_yticks([i + 0.5 for i in range(len(row_labels))])
    ax.set_xticklabels(column_labels, rotation = (45), fontsize = 10, va='bottom')#, fontweight = 'demi')
    ax.set_yticklabels(row_labels, fontsize = 9, fontstyle='italic')
    
    cbar = plt.colorbar(heatmap)
    help(ax.set_xticklabels)
    ax.margins(x=0.01,y=0.01)
    fig.set_size_inches(20, 13)
    plt.savefig('figure.png')
    


Answer: you have to set the horizontal alignment of the labels to `left` in your case.
They are centered by default. [The
link](http://stackoverflow.com/a/14854007/588071) from @Jean-Sébastien
contains your answer

    
    
    ax.set_xticklabels(column_labels, rotation = (45), fontsize = 10, va='bottom', ha='left')
    

