Skip to content

Commit ef3ac71

Browse files
feat: hist2dplot labels options (#547)
* more labels args * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent bbc23b2 commit ef3ac71

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/mplhep/plot.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,9 @@ def hist2dplot(
655655
xbins=None,
656656
ybins=None,
657657
labels=None,
658+
labels_fontsize=None,
659+
labels_round=None,
660+
labels_color=None,
658661
cbar: bool = True,
659662
cbarsize="7%",
660663
cbarpad=0.2,
@@ -686,6 +689,12 @@ def hist2dplot(
686689
labels : 2D array (H-like) or bool, default None, optional
687690
Array of per-bin labels to display. If ``True`` will
688691
display numerical values
692+
labels_fontsize : float, optional, default None
693+
Fontsize of labels.
694+
labels_color : str, optional, default None
695+
Color of labels. If not given, will be decided automatically.
696+
labels_round : int, optional, default None
697+
Round labels to given number of decimals
689698
cbar : bool, optional, default True
690699
Draw a colorbar. In contrast to mpl behaviors the cbar axes is
691700
appended in such a way that it doesn't modify the original axes
@@ -971,15 +980,21 @@ def hist2dplot(
971980
for ix, xc in enumerate(xbin_centers):
972981
for iy, yc in enumerate(ybin_centers):
973982
normedh = pc.norm(H[iy, ix])
974-
color = "black" if isLight(pccmap(normedh)[:-1]) else "lightgrey"
983+
if labels_color is not None:
984+
color = labels_color
985+
else:
986+
color = "black" if isLight(pccmap(normedh)[:-1]) else "lightgrey"
975987
text_artists.append(
976988
ax.text(
977989
xc,
978990
yc,
979-
_labels[iy, ix], # type: ignore[arg-type]
991+
_labels[iy, ix].round(labels_round)
992+
if labels_round is not None
993+
else _labels[iy, ix], # type: ignore[arg-type]
980994
ha="center",
981995
va="center",
982996
color=color,
997+
fontsize=labels_fontsize,
983998
)
984999
)
9851000

0 commit comments

Comments
 (0)