update matplotlib code from blog