mpl_code_Triangle.py 726 B

123456789101112131415161718192021222324252627282930
  1. import matplotlib.pyplot as mpl
  2. import matplotlib.transforms as transforms
  3. mpl.ion() # for interactive drawing
  4. fig = mpl.figure()
  5. ax = fig.gca()
  6. xmin, xmax, ymin, ymax = 0.0, 8.0, -1.5, 3.6
  7. ax.set_xlim(xmin, xmax)
  8. ax.set_ylim(ymin, ymax)
  9. ax.set_aspect('equal')
  10. mpl.grid(True)
  11. # triangle
  12. x = [2.0, 6.0, 3.2, 2.0]
  13. y = [0.0, 2.0, 3.0, 0.0]
  14. [line] = ax.plot(x, y, 'b', linewidth=2, linestyle='solid')
  15. ax.text(6, 2, 'p2',
  16. horizontalalignment='center', fontsize=14)
  17. ax.text(3.2, 3, 'p3',
  18. horizontalalignment='center', fontsize=14)
  19. ax.text(2, 0, 'p1',
  20. horizontalalignment='center', fontsize=14)
  21. mpl.title("Triangle")
  22. mpl.draw()
  23. mpl.savefig("tmp_Triangle.png", dpi=None)
  24. mpl.savefig("tmp_Triangle.pdf")