Matplotlib + Seaborn savefig文本变成了框

时间:2014-12-17 21:25:33

标签: python matplotlib seaborn

我用seaborn制作小提琴情节。当我尝试使用matplotlib保存图形时,我得到这样的结果:

enter image description here

为什么我得到一堆盒子而不是x轴和y轴的实际文本?

我的代码如下:

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')

0 个答案:

没有答案