improved printgraph()