[Fix] Update plotting imports and thread handling in Pepper class (#382)

- plt.subplot does not work reliably with async/ threads.
- Bug in thread run that would fail with env set (string to number)

Reviewed-on: enviPath/enviPy#382
Co-authored-by: Tobias O <tobias.olenyi@envipath.com>
Co-committed-by: Tobias O <tobias.olenyi@envipath.com>
This commit is contained in:
2026-05-12 06:43:26 +12:00
committed by jebus
parent 9d70db2ca2
commit 734b02767e
2 changed files with 7 additions and 6 deletions

View File

@ -46,7 +46,7 @@ class PepperPrediction(PropertyPrediction):
import matplotlib.patches as mpatches
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.figure import Figure
from scipy import stats
"""
@ -101,7 +101,8 @@ class PepperPrediction(PropertyPrediction):
mask_red = x > vp
# Plot
fig, ax = plt.subplots(figsize=(9, 5.5))
fig = Figure(figsize=(9, 5.5))
ax = fig.subplots()
ax.plot(x, y, color="#1f4e79", lw=2, label="Lognormal PDF")
if np.any(mask_green):
@ -146,13 +147,12 @@ class PepperPrediction(PropertyPrediction):
]
ax.legend(handles=patches, frameon=True)
plt.tight_layout()
fig.tight_layout()
# --- Export to SVG string ---
buf = io.StringIO()
fig.savefig(buf, format="svg", bbox_inches="tight")
svg = buf.getvalue()
plt.close(fig)
buf.close()
return svg