轴方向演示步骤02

轴方向演示步骤02示例

  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[:].toggle(all=False)
  9. #ax.axis[:].line.set_visible(False)
  10. ax.axis[:].set_visible(False)
  11. ax.axis["x"] = ax.new_floating_axis(1, 0.5)
  12. ax.axis["x"].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["x"].set_ticklabel_direction("+")
  18. ax1.annotate("ticklabel direction=$+$", (0.5, 0), xycoords="axes fraction",
  19. xytext=(0, -10), textcoords="offset points",
  20. va="top", ha="center")
  21. ax2 = setup_axes(fig, "122")
  22. ax2.axis["x"].set_ticklabel_direction("-")
  23. ax2.annotate("ticklabel direction=$-$", (0.5, 0), xycoords="axes fraction",
  24. xytext=(0, -10), textcoords="offset points",
  25. va="top", ha="center")
  26. plt.show()

下载这个示例