Shakespeare's plot is only partly based on fact. Macbeth was a real eleventh century Scottish king, but the historical Macbeth, who had a valid right to the throne, reigned capably in Scotland from 1040 till 1057. He succeeded Duncan, whom he had defeated in battle, but the real Duncan was a weak man, around Macbeth's own age, not the respected elderly figure we meet in the play. In reality, Macbeth was succeeded by his own stepson, not by Duncan's son, Malcolm, who came to the throne later. Read the full article
Shakespeare enjoyed much support for Queen Elizabeth who encouraged the artistic efforts of her subjects during the creative Renaissance years. After her death, James VI of Scotland became James I, King of England, in 1603. Because James was considered the eighth descendant of the Banquo-Fleance line, Shakespeare "polished" the historical representation to present Banquo's character in a more honorable light. The Banquo of Holinshed's Chronicles is actually involved in the conspiracy to murder King Duncan.
Read more at http://www.penguin.com/static/pdf/teachersguides/macbeth.pdf
It is important to understand the political context in which it was written, as that is the key to the main theme of the play, which is that excessive ambition will have terrible consequences. Shakespeare was writing for the theatre during the reigns of two monarchs, Queen Elizabeth I and King James I. The plays he wrote during the reign of Queen Elizabeth, such as A Midsummer Night's Dream, are often seen to embody the generally happy, confident and optimistic mood of the Elizabethans. However, those he wrote during James's reign, such as Macbeth and Hamlet, are darker and more cynical, reflecting the insecurities of the Jacobean period. Macbeth was written the year after the Gunpowder Plot of 1605. Read full text