Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
My 2014 imac was fine in El Cap, but when I got Sierra it too began going crazy (similar to OP but not identical) when I would plug my 4k monitor in, put the mac to sleep and then wake it. The main screen would go crazy for a few seconds similar to OP's, then it would just go black (on but black) and the 4k would just be solid green.

Yeah I only see the scrambled color bars on shutdown and then only if my second monitor is off at the time (I usually turn it off after I initiate shutdown).
 
I had the same problem.

Beta 3 & 4 seem to have resolved the glitch during restart.
 
Haven't yet installed the latest update, will do later on. Hopefully it fixes it otherwise I will be taking it back.
 
In March I purchased a late 2015 5k iMac for myself, mostly to replace my 2013 MacBook Pro.

Until around 3 weeks ago it worked perfectly, no complaints. I restarted the iMac one night, the screen appeared to go black but then a green screen appeared with black lines through the centre. The iMac restarted and thought nothing of it. iMac powered on, used it and then switched off.

The next day I switched on my iMac, used it and then powered off. The green screen appeared again. So I decided to do a fresh OS install. A couple of days had passed and after a couple of restarts, I was then greeted with a blue screen with purple lines. I then decided to contact Apple Support, followed their advice with the PRAM reset, SMC and fresh install. This didn't solve my issue so I took it into my local Apple Store (frustrating as I don't drive!).

In store they decided that the logic board had failed and needed replacing, so they did. After 6 days of waiting, I got the call to pick it up. The advised the logic board had been repaired, the iMac had been 'stress' tested and all was ok.

This afternoon I've just restarted my iMac and hello blue and purple screen. Any idea's what could be causing this if it's not the logic board? I'm so tired of having to complain to Apple, my 2013 MacBook Pro had it's logic board replaced twice.
It's a Sierra glitch! No need to have them fiddling around with your iMac..... opening it up and replacing parts they're not sure of. I didn't experience it until I update to Sierra from El Cap. I even did a clean install of Sierra to.
 
iMac (Retina 5K, 27-inch, Late 2015), bought late January, came with 10.12.2, updated 10.12.3. Has done it with both versions on shutdown.

3.2 GHz Intel Core i5
16 GB 1867 MHz DDR3
AMD Radeon R9 M390 2048 MB
 
It's a Sierra glitch! No need to have them fiddling around with your iMac..... opening it up and replacing parts they're not sure of. I didn't experience it until I update to Sierra from El Cap. I even did a clean install of Sierra to.

Took it to the Apple Store, they were great. Gave me a replacement iMac as they couldn't diagnose the fault.
The latest update to OS has fixed it (for me anyway!).
 
In March I purchased a late 2015 5k iMac for myself, mostly to replace my 2013 MacBook Pro.

Until around 3 weeks ago it worked perfectly, no complaints. I restarted the iMac one night, the screen appeared to go black but then a green screen appeared with black lines through the centre. The iMac restarted and thought nothing of it. iMac powered on, used it and then switched off.

The next day I switched on my iMac, used it and then powered off. The green screen appeared again. So I decided to do a fresh OS install. A couple of days had passed and after a couple of restarts, I was then greeted with a blue screen with purple lines. I then decided to contact Apple Support, followed their advice with the PRAM reset, SMC and fresh install. This didn't solve my issue so I took it into my local Apple Store (frustrating as I don't drive!).

In store they decided that the logic board had failed and needed replacing, so they did. After 6 days of waiting, I got the call to pick it up. The advised the logic board had been repaired, the iMac had been 'stress' tested and all was ok.

This afternoon I've just restarted my iMac and hello blue and purple screen. Any idea's what could be causing this if it's not the logic board? I'm so tired of having to complain to Apple, my 2013 MacBook Pro had it's logic board replaced twice.
It seems like a software glitch, I get the same often, but not always. I was worried first, but now just ignore it.
 
Yeah it seems to be specific to Sierra (10.12). Have not seen it since going to 10.12.4 (and not very often on 10.12.3) so hopefully they're tracing whatever in macOS is causing it and eliminating it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.