简单寄生示例2

简单寄生示例2

  1. import matplotlib.transforms as mtransforms
  2. import matplotlib.pyplot as plt
  3. from mpl_toolkits.axes_grid1.parasite_axes import SubplotHost
  4. obs = [["01_S1", 3.88, 0.14, 1970, 63],
  5. ["01_S4", 5.6, 0.82, 1622, 150],
  6. ["02_S1", 2.4, 0.54, 1570, 40],
  7. ["03_S1", 4.1, 0.62, 2380, 170]]
  8. fig = plt.figure()
  9. ax_kms = SubplotHost(fig, 1, 1, 1, aspect=1.)
  10. # angular proper motion("/yr) to linear velocity(km/s) at distance=2.3kpc
  11. pm_to_kms = 1./206265.*2300*3.085e18/3.15e7/1.e5
  12. aux_trans = mtransforms.Affine2D().scale(pm_to_kms, 1.)
  13. ax_pm = ax_kms.twin(aux_trans)
  14. ax_pm.set_viewlim_mode("transform")
  15. fig.add_subplot(ax_kms)
  16. for n, ds, dse, w, we in obs:
  17. time = ((2007 + (10. + 4/30.)/12) - 1988.5)
  18. v = ds / time * pm_to_kms
  19. ve = dse / time * pm_to_kms
  20. ax_kms.errorbar([v], [w], xerr=[ve], yerr=[we], color="k")
  21. ax_kms.axis["bottom"].set_label("Linear velocity at 2.3 kpc [km/s]")
  22. ax_kms.axis["left"].set_label("FWHM [km/s]")
  23. ax_pm.axis["top"].set_label(r"Proper Motion [$''$/yr]")
  24. ax_pm.axis["top"].label.set_visible(True)
  25. ax_pm.axis["right"].major_ticklabels.set_visible(False)
  26. ax_kms.set_xlim(950, 3700)
  27. ax_kms.set_ylim(950, 3100)
  28. # xlim and ylim of ax_pms will be automatically adjusted.
  29. plt.show()

下载这个示例