Skip to content

Commit 2bea2b0

Browse files
committed
feat(matrix): add xlabel and ylabel parameters for axis labels
- Add optional `xlabel` and `ylabel` parameters to matrix plot function - Update function documentation to include new parameters - Modify return type annotation from AxesImage to Axes for accuracy - Implement axis label setting logic with conditional checks Closes #56
1 parent 8bbbeb3 commit 2bea2b0

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/plotfig/matrix.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def plot_matrix_figure(
3333
title_fontsize: Num = 15,
3434
title_pad: Num = 20,
3535
diag_border: bool = False,
36+
xlabel: str | None = None,
37+
ylabel: str | None = None,
3638
**imshow_kwargs: Any,
3739
) -> Axes:
3840
"""
@@ -60,10 +62,12 @@ def plot_matrix_figure(
6062
title_fontsize (Num): 标题的字体大小。
6163
title_pad (Num): 标题上方的间距。
6264
diag_border (bool): 是否绘制对角线单元格边框。
65+
xlabel (str | None): X轴的整体标签名称。
66+
ylabel (str | None): Y轴的整体标签名称。
6367
**imshow_kwargs (Any): 传递给 `imshow()` 的其他关键字参数。
6468
6569
Returns:
66-
AxesImage: 由 `imshow()` 创建的图像对象
70+
Axes: 绘图的坐标轴对象
6771
"""
6872

6973
ax = ax or plt.gca()
@@ -74,6 +78,13 @@ def plot_matrix_figure(
7478
data, cmap=cmap, vmin=vmin, vmax=vmax, aspect=aspect, **imshow_kwargs
7579
)
7680
ax.set_title(title_name, fontsize=title_fontsize, pad=title_pad)
81+
82+
# 设置X轴和Y轴标签
83+
if xlabel is not None:
84+
ax.set_xlabel(xlabel)
85+
if ylabel is not None:
86+
ax.set_ylabel(ylabel)
87+
7788
if diag_border:
7889
for i in range(data.shape[0]):
7990
ax.add_patch(
@@ -116,4 +127,3 @@ def plot_matrix_figure(
116127
)
117128

118129
return ax
119-

0 commit comments

Comments
 (0)