Log multiple variables at the same plot from program

In Log multiple variables at the same plot is described how to combine via the GUI, which is at least cumbersome.

How can I achieve combining train, val and test loss directly from software? Is it possible to reach it via an API?