Fix the matplotlib warnings

See #2822.