Skip to content

Commit d0f19a1

Browse files
add option to control labels in legend #43
1 parent 3e373ef commit d0f19a1

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ uv.lock
2222
!sample.csv
2323
*.zip
2424

25-
scripts/release.sh
25+
release.sh

dayplot/calendar.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ def calendar(
153153
legend_labels: Optional[Union[List, Literal["auto"]]] = None,
154154
legend_labels_precision: Optional[int] = None,
155155
legend_labels_kws: Optional[Dict] = None,
156+
less_label: str = "Less",
157+
more_label: str = "More",
156158
clip_on: bool = False,
157159
ax: Optional[Axes] = None,
158160
**kwargs: Any,
@@ -220,6 +222,8 @@ def calendar(
220222
`legend_labels="auto"`.
221223
legend_labels_kws: Additional keyword arguments passed to the matplotlib text
222224
function when rendering legend labels.
225+
less_label: Left label used for the legend.
226+
more_label: Right label used for the legend.
223227
clip_on: Whether the artist (e.g., squares) is clipped to the axes boundaries (True) or allowed to extend
224228
beyond them (False).
225229
ax: A matplotlib axes. If None, plt.gca() will be used. It is advisable to make this explicit
@@ -377,7 +381,7 @@ def calendar(
377381
legend_labels_style.update(legend_labels_kws)
378382
ax.text(x=i + 0.5, y=9, s=legend_label, **legend_labels_style) # type: ignore[invalid-argument-type]
379383

380-
ax.text(-0.6, 8, "Less", va="center", ha="right", size=8)
381-
ax.text(legend_bins + 0.5, 8, "More", va="center", ha="left", size=8)
384+
ax.text(-0.6, 8, less_label, va="center", ha="right", size=8)
385+
ax.text(legend_bins + 0.5, 8, more_label, va="center", ha="left", size=8)
382386

383387
return rect_patches

tests/test_main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,11 @@ def test_diffrerent_df_backends(backend):
216216
@pytest.mark.parametrize("legend_bins", [2, 4, 10])
217217
@pytest.mark.parametrize("legend_labels", [None, "auto", []])
218218
@pytest.mark.parametrize("legend_labels_kws", [None, {"color": "red", "size": "10"}])
219-
def test_legend_works(legend, legend_bins, legend_labels, legend_labels_kws):
219+
@pytest.mark.parametrize("less_label", ["Less", "Moins"])
220+
@pytest.mark.parametrize("more_label", ["More", "Plus"])
221+
def test_legend_works(
222+
legend, legend_bins, legend_labels, legend_labels_kws, less_label, more_label
223+
):
220224
"""Test that legend arguments work"""
221225
dates = [datetime(2024, 1, 1) + timedelta(days=i) for i in range(7)]
222226
values = [1, 2, 3, 4, 5, 6, 7]
@@ -230,6 +234,8 @@ def test_legend_works(legend, legend_bins, legend_labels, legend_labels_kws):
230234
legend_bins=legend_bins,
231235
legend_labels=legend_labels,
232236
legend_labels_kws=legend_labels_kws,
237+
less_label=less_label,
238+
more_label=more_label,
233239
)
234240

235241
patches = ax.patches

0 commit comments

Comments
 (0)