Matplotlib text + Seaborn savefig turns into boxes

I used the seabed to create a violin plot. When I try to save a figure using matplotlib I get something like this:

enter image description here

Why am I getting a bunch of boxes and not actual text for the x and y axes?

My code is below:

for i, column in enumerate(data.columns[6:]):
    groups = list(np.unique(data['Group'].values))
    days = list(np.unique(data['Day sacrificed'].values))

    groups_days = list(product(groups, days))
    colors = ['r', 'g', 'b', 'y']
    shapes = ['>', '<', 'o', '^']
    fig = plt.figure(i)

    pos = []
    d = []
    for (group, day), df in data.groupby(['Group', 'Day sacrificed']):
        pos.append(groups_days.index((group, day)))
        if len(set(df[column].values)) == 1:

            d.append([df[column].values[0]])
        else:
            d.append(df[column].values)
    seaborn.violinplot(d, pos)
    colnames = [u'{0} {1}'.format(i,j) for i, j in groups_days]
    plt.xlim(-1, len(colnames))
    plt.xticks(range(len(colnames)), colnames, rotation='vertical')
    plt.xlabel('Grouping')
    plt.title(u'{0}'.format(column))
    plt.ylabel(u'{0}'.format(column))
    fig = plt.gcf()
    plt.savefig('{0}.pdf'.format(column.replace('/', '_')), bbox_inches='tight')

      

+3


source to share





All Articles