|
1 | | -""" pyplots.ai |
| 1 | +"""pyplots.ai |
2 | 2 | heatmap-basic: Basic Heatmap |
3 | 3 | Library: seaborn 0.13.2 | Python 3.14.3 |
4 | 4 | Quality: 82/100 | Updated: 2026-02-15 |
|
25 | 25 | data = np.clip(data, 5, 95) |
26 | 26 |
|
27 | 27 | # Plot - clustermap groups similar departments via hierarchical clustering |
28 | | -cmap = sns.diverging_palette(240, 10, as_cmap=True) |
29 | 28 | g = sns.clustermap( |
30 | 29 | data, |
31 | 30 | annot=True, |
32 | 31 | fmt=".0f", |
33 | | - cmap=cmap, |
| 32 | + cmap="coolwarm", |
34 | 33 | center=50, |
35 | 34 | xticklabels=months, |
36 | 35 | yticklabels=departments, |
37 | | - linewidths=1, |
| 36 | + linewidths=1.5, |
38 | 37 | linecolor="white", |
39 | | - annot_kws={"fontsize": 14}, |
| 38 | + annot_kws={"fontsize": 16, "fontweight": "medium"}, |
40 | 39 | figsize=(16, 10), |
41 | 40 | row_cluster=True, |
42 | 41 | col_cluster=False, |
43 | 42 | dendrogram_ratio=0.08, |
44 | | - cbar_pos=None, |
| 43 | + cbar_pos=(0.02, 0.15, 0.03, 0.6), |
| 44 | + cbar_kws={"label": "Performance Score", "ticks": [0, 25, 50, 75, 100]}, |
45 | 45 | vmin=0, |
46 | 46 | vmax=100, |
47 | 47 | ) |
48 | 48 |
|
49 | | -# Colorbar with proper placement |
50 | | -sm = plt.cm.ScalarMappable(cmap=cmap, norm=plt.Normalize(0, 100)) |
51 | | -cbar = g.fig.colorbar(sm, ax=g.ax_heatmap, location="right", shrink=0.7, pad=0.12) |
52 | | -cbar.set_label("Performance Score", fontsize=18) |
53 | | -cbar.ax.tick_params(labelsize=14) |
| 49 | +# Colorbar styling |
| 50 | +g.cax.set_ylabel("Performance Score", fontsize=18, labelpad=10) |
| 51 | +g.cax.tick_params(labelsize=14) |
| 52 | +g.cax.yaxis.set_label_position("left") |
54 | 53 |
|
55 | | -# Style |
56 | | -g.ax_heatmap.set_xlabel("Month", fontsize=20) |
57 | | -g.ax_heatmap.set_ylabel("") |
| 54 | +# Labels and title |
| 55 | +g.ax_heatmap.set_xlabel("Month", fontsize=20, labelpad=12) |
| 56 | +g.ax_heatmap.set_ylabel("Department", fontsize=20, labelpad=12) |
58 | 57 | g.ax_heatmap.tick_params(axis="x", labelsize=16) |
59 | 58 | g.ax_heatmap.tick_params(axis="y", labelsize=16, rotation=0) |
60 | | -g.fig.suptitle("heatmap-basic · seaborn · pyplots.ai", fontsize=24, y=1.02) |
61 | 59 |
|
62 | | -plt.savefig("plot.png", dpi=300, bbox_inches="tight") |
| 60 | +# Visual refinement - remove heatmap spines for cleaner look |
| 61 | +for spine in g.ax_heatmap.spines.values(): |
| 62 | + spine.set_visible(False) |
| 63 | + |
| 64 | +# Style the dendrogram |
| 65 | +g.ax_row_dendrogram.set_facecolor("#f8f8f8") |
| 66 | +for spine in g.ax_row_dendrogram.spines.values(): |
| 67 | + spine.set_visible(False) |
| 68 | + |
| 69 | +# Background refinement |
| 70 | +g.fig.patch.set_facecolor("#fafafa") |
| 71 | +g.ax_heatmap.set_facecolor("white") |
| 72 | + |
| 73 | +# Title |
| 74 | +g.fig.suptitle("heatmap-basic · seaborn · pyplots.ai", fontsize=24, fontweight="medium", y=1.02, color="#333333") |
| 75 | + |
| 76 | +plt.savefig("plot.png", dpi=300, bbox_inches="tight", facecolor=g.fig.get_facecolor()) |
0 commit comments