Matplotlib problems

Hi! I am new to Slicer. I am trying to save a plot by script

plt.scatter(np.arange(1, 20, 1), np.arange(1,20, 1))
plt.savefig(os.path.join(results_path, "plotloss.png"))

from slicer. The plot has some additional values, I cannot figure out where they come from. When running the same script from Spyder everything works fine.

Can you provide a complete example, ideally with images to show what you mean by additional values?

After adding the necessary imports, it all worked correctly for me:

pip_install("matplotlib wxPython")

import matplotlib
matplotlib.use('WXAgg')

from matplotlib import pyplot as plt
import numpy as np

plt.scatter(np.arange(1, 20, 1), np.arange(1,20, 1))
plt.savefig("c:/tmp/plotloss.png")

Produced this:

image

Interesting. Thank you for your answer. Looks like restarting slicer was the solution. My loss was previously accumulating like this: