Skip to content

Commit 95367dd

Browse files
Flix6xclaude
andcommitted
Move the label "feed-in price below zero" clear of the legend in the day picture
It sat at the top of the shaded hours, where the legend's "with reaction rules" runs; it now sits low in them, above the zero line, where no series is drawn. A test draws the picture and checks that the label's box and the legend's do not overlap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: F.N. Claessen <claessen@seita.nl>
1 parent 65e875e commit 95367dd

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎examples/reaction_rules_saldering.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,10 @@ def plot_day(day: Day, path: Path) -> None:
360360
ha="left",
361361
va="center",
362362
)
363+
# Low in the shaded hours, under the legend that runs along the top.
363364
ax_meter.text(
364365
12.05,
365-
4.4,
366+
1.3,
366367
"feed-in price below zero",
367368
color="#8a5d00",
368369
fontsize=8.5,

‎tests/examples/test_reaction_rules_saldering.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,25 @@ def test_the_guide_tells_the_cost_the_bars_show():
9999
# "A few cents" is only said of the saldering day, the bar that is that close.
100100
assert "within a few cents of what it cost under saldering" in sentence
101101
assert abs(numbers["cost_reaction"] - numbers["cost_saldering_plain"]) < 0.1
102+
103+
104+
def test_the_negative_price_label_stays_clear_of_the_legend(tmp_path, monkeypatch):
105+
"""In the day picture's middle panel, the label on the shaded hours does not run into the legend."""
106+
pytest.importorskip("matplotlib")
107+
import matplotlib.pyplot as plt
108+
109+
figures = []
110+
monkeypatch.setattr(plt, "close", figures.append)
111+
example.plot_day(example.simulate(), tmp_path / "reaction-rules-day.png")
112+
(figure,) = figures
113+
renderer = figure.canvas.get_renderer()
114+
ax_meter = figure.axes[1]
115+
116+
(label,) = [
117+
text for text in ax_meter.texts if text.get_text() == "feed-in price below zero"
118+
]
119+
legend = ax_meter.get_legend()
120+
assert not label.get_window_extent(renderer).overlaps(
121+
legend.get_window_extent(renderer)
122+
)
123+
plt.close(figure)

0 commit comments

Comments
 (0)