def draw(self):
""" Draw a heat map. """
def get_crosstab(data, row_fact,col_fact, row_names, col_names):
ct = pd.crosstab(data[row_fact], data[col_fact])
ct = ct.reindex_axis(row_names, axis=0).fillna(0)
ct = ct.reindex_axis(col_names, axis=1).fillna(0)
return ct
def plot(data, color):
ct = get_crosstab(
data,
self._groupby[0],
self._groupby[1],
self._levels[0],
self._levels[1])
sns.heatmap(ct,
robust=True,
annot=True,
cbar=False,
cmap=cmap,
fmt="g",
vmax=vmax,
#ax=plt.gca(),
linewidths=1)
if len(self._groupby) < 2:
# create a dummy cross tab with one dimension containing empty
# values:
data_column = self._table[self._groupby[0]].reset_index(drop=True)
tab = pd.crosstab(
pd.Series([""] * len(data_column), name=""),
data_column)
plot_facet = lambda data, color: sns.heatmap(
tab,
robust=True,
annot=True,
cbar=False,
cmap=cmap,
fmt="g",
linewidths=1)
else:
plot_facet = plot
vmax = pd.crosstab(
[self._table[x] for x in [self._row_factor, self._groupby[0]] if x != None],
[self._table[x] for x in [self._col_factor, self._groupby[1]] if x != None]).values.max()
cmap = ListedColormap(self.options["color_palette_values"])
self.map_data(plot_facet)
评论列表
文章目录