pandas/seaborn - how to improve the appearance of

2019-03-05 03:27发布

问题:

I get a horrible looking heatmap using the code and datafile below. What am I doing wrong? How can I make it so that it's a square looking grid and the tick labels are better looking too?

Datafile

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(color_codes=True)
np.random.seed(sum(map(ord, "distributions")))

data = pd.read_csv('heatmap.dat',sep='\s',engine='python')

data2 = pd.pivot_table(data,values='f',index='d',columns='e')

mask = np.isnan(data2)

sns.set(style="white")

ax = sns.heatmap(data2, vmin=None, vmax=None, cmap="afmhot", 
                 center=None, robust=False, annot=False, fmt='.2g', 
                 annot_kws=None, linewidths=0, linecolor='white', 
                 cbar=True, cbar_kws=None, cbar_ax=None, square=True, 
                 ax=None,xticklabels=100,yticklabels=10,  mask=mask)

plt.title('Heatmap')
plt.xlabel('angle')
plt.ylabel('mass_fraction')

ax.invert_yaxis()

plt.savefig('heatmap.png', transparent=True)

sns.plt.show()