def __init__(self, parent, data, labels, width=6, height=6, dpi=100):
figure = Figure(figsize=(width, height), dpi=dpi, tight_layout=True)
axes = figure.add_subplot(111)
super(CorrelationPlot, self).__init__(figure)
self.setParent(parent)
sns.set(style="darkgrid")
corr = data
# cmap = sns.diverging_palette(220, 10, as_cmap=True)
# corrplot(data, names=labels, annot=True, sig_stars=False,
# diag_names=True, cmap=cmap, ax=axes, cbar=True)
df = pd.DataFrame(data=data, columns=labels)
corr = df.corr()
# Generate a mask for the upper triangle
mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True
# Draw the heatmap with the mask and correct aspect ratio
vmax = np.abs(corr.values[~mask]).max()
# vmax = np.abs(corr).max()
sns.heatmap(corr, mask=mask, cmap=plt.cm.PuOr, vmin=-vmax, vmax=vmax,
square=True, linecolor="lightgray", linewidths=1, ax=axes)
for i in range(len(corr)):
axes.text(i + 0.5, i + 0.5, corr.columns[i],
ha="center", va="center", rotation=0)
for j in range(i + 1, len(corr)):
s = "{:.3f}".format(corr.values[i, j])
axes.text(j + 0.5, i + 0.5, s,
ha="center", va="center")
axes.axis("off")
# If uncommented, fills widget
self.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
self.updateGeometry()
self.setMinimumSize(self.size())
评论列表
文章目录