Assuming you can’t pick your own layouts in-game, the positioning will depend on the amount of pets you have. It means that certain amount of pets (like 5 and 3 as seen in the screenshots) have a custom arrangement, and every other amount is automatically organized into some pattern (like a circle).
Actually implementing them is the hard part, but I figure there’s more than enough resources for doing this. As an example, How to create a pet system that dynamically generates positions.
If you can’t find these posts with the DevForum’s search engine (because it SUCKS), you can always use Google or DuckDuckGo, like so: Google Search.
Good luck!