Obligatory mention: if you can use libraries, you might want to use grafica:
https://jagracar.com/sketches/multiplePlots.php
It has a lot of the things you want – axis labeling, grid lines, scaling, etc – already implemented, you just need to look at the examples and adapt them to your data.