轴方向演示步骤04

轴方向演示步骤04示例

  1. import matplotlib.pyplot as plt
  2. import mpl_toolkits.axisartist as axisartist
  3. def setup_axes(fig, rect):
  4. ax = axisartist.Subplot(fig, rect)
  5. fig.add_axes(ax)
  6. ax.set_ylim(-0.1, 1.5)
  7. ax.set_yticks([0, 1])
  8. ax.axis[:].set_visible(False)
  9. ax.axis["x1"] = ax.new_floating_axis(1, 0.3)
  10. ax.axis["x1"].set_axisline_style("->", size=1.5)
  11. ax.axis["x2"] = ax.new_floating_axis(1, 0.7)
  12. ax.axis["x2"].set_axisline_style("->", size=1.5)
  13. return ax
  14. fig = plt.figure(figsize=(6, 2.5))
  15. fig.subplots_adjust(bottom=0.2, top=0.8)
  16. ax1 = setup_axes(fig, "121")
  17. ax1.axis["x1"].label.set_text("rotation=0")
  18. ax1.axis["x1"].toggle(ticklabels=False)
  19. ax1.axis["x2"].label.set_text("rotation=10")
  20. ax1.axis["x2"].label.set_rotation(10)
  21. ax1.axis["x2"].toggle(ticklabels=False)
  22. ax1.annotate("label direction=$+$", (0.5, 0), xycoords="axes fraction",
  23. xytext=(0, -10), textcoords="offset points",
  24. va="top", ha="center")
  25. ax2 = setup_axes(fig, "122")
  26. ax2.axis["x1"].set_axislabel_direction("-")
  27. ax2.axis["x2"].set_axislabel_direction("-")
  28. ax2.axis["x1"].label.set_text("rotation=0")
  29. ax2.axis["x1"].toggle(ticklabels=False)
  30. ax2.axis["x2"].label.set_text("rotation=10")
  31. ax2.axis["x2"].label.set_rotation(10)
  32. ax2.axis["x2"].toggle(ticklabels=False)
  33. ax2.annotate("label direction=$-$", (0.5, 0), xycoords="axes fraction",
  34. xytext=(0, -10), textcoords="offset points",
  35. va="top", ha="center")
  36. plt.show()

下载这个示例