轴方向演示步骤03

轴方向演示步骤03示例

  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"].label.set_text("Label")
  18. ax1.axis["x"].toggle(ticklabels=False)
  19. ax1.axis["x"].set_axislabel_direction("+")
  20. ax1.annotate("label direction=$+$", (0.5, 0), xycoords="axes fraction",
  21. xytext=(0, -10), textcoords="offset points",
  22. va="top", ha="center")
  23. ax2 = setup_axes(fig, "122")
  24. ax2.axis["x"].label.set_text("Label")
  25. ax2.axis["x"].toggle(ticklabels=False)
  26. ax2.axis["x"].set_axislabel_direction("-")
  27. ax2.annotate("label direction=$-$", (0.5, 0), xycoords="axes fraction",
  28. xytext=(0, -10), textcoords="offset points",
  29. va="top", ha="center")
  30. plt.show()

下载这个示例