Firstly you will need an image where the subject has a well defined edge against the background. For my example I'm using the picture of my clockwork robot.
Now go to image>adjustments>threshold.
Now move the sliding threshold scale so the image is silhouetted
You should have the main subject nicely darkened as in the example above.
Next move the 'new layer' down so it sits underneath your image in the layers palette (See arrow) and then highlight the top layer by clicking once on it.
Now go to edit>cut. This removes the white from the background
Click the bottom layer (1) and then select the gradient tool (2). You may wish to use one of the preselected colours in the menu (3) or select your own colours from the colour palette (4)
For this example I'm choosing preselected colours from the top menu.
Holding your left mouse button down at the top of the image, drag a line all the way down to the bottom. You may wish to draw the line diagonally across the image or from the bottom to the top. The choice is yours. Once you've done this let go of the mouse button and the graduated background will be applied. N.B. If your picture disappears and all you have is a graduated colour this is because the wrong layer has been selected - make sure your picture is highlighted blue in the layers palette.