William Shakespeare wrote "Macbeth" as a way to express his patronage of King James I. Shakespeare uses "Macbeth" to please the king in various manners, with one of them alluding to the dreadful fate that befalls anyone who tries to take over the throne.
"Macbeth" relates the story of someone who overthrows the King of Scotland by killing him. This is similar to the Gunpowder Plot of 1605, when there was an attempt made by a group of rebel Catholics to kill King James I and blow up the parliament. In addition, the mention of the witches in Shakespeare's tragedy coincides with James' enthusiasm with the subject of witches.
Another important aspect of "Macbeth" is that it is the only Shakespearean play that is set in Scotland. This helped to legitimize King James' rightful succession to the throne of England, as he was the son of Mary Queen of Scots.