modified for matplotlib