Added matplotlib imports and usage that prevents errors in servers without X