Select two parameters and dependent variable from a DataFrame and plot an ´imshow´-style heatmap with isocontours.
Remember to:
import seaborn as sns
Select two parameters and dependent variable from a DataFrame and plot an ´imshow´-style heatmap with isocontours.
Remember to:
import seaborn as sns
grid = df.pivot_table(index='param1', columns='param2', values='values') | |
f, ax = plt.subplots(figsize=(9, 6)) | |
sns.heatmap(grid, annot=False, cmap='magma', linewidths=.0, fmt='.3f', square=True, | |
ax=ax, annot_kws={"fontsize": 15}, cbar_kws={'label': 'values'}) | |
ax.set_xlabel(ax.get_xlabel(), fontsize=14) | |
ax.set_ylabel(ax.get_ylabel(), fontsize=14) | |
# plot contours | |
z = scipy.ndimage.zoom(grid.to_numpy(), 2, order=1) | |
IC = ax.contour( | |
np.linspace(0, len(grid.columns), len(grid.columns) * 2), | |
np.linspace(0, len(grid.index), len(grid.index) * 2), | |
z, levels=[100, 150, 200, 250, 300, 500, 1000, 1500, 2000], linestyles='dashed', cmap='spring' | |
) | |
plt.clabel(IC, inline=True, fontsize=15) # add text to contours | |
plt.show() |