Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double x-axis in one plot #5

Open
Fil8 opened this issue Aug 27, 2018 · 1 comment
Open

Double x-axis in one plot #5

Fil8 opened this issue Aug 27, 2018 · 1 comment
Labels
bug Something isn't working ToDo

Comments

@Fil8
Copy link
Collaborator

Fil8 commented Aug 27, 2018

Output spectra should have a double x-axis:

  • frequency in GHz
  • velocity (cz)

and an option to plot a vertical line at the redshift/expected HI frequency of the galaxy.

@Fil8 Fil8 added bug Something isn't working ToDo labels Aug 27, 2018
@Fil8
Copy link
Collaborator Author

Fil8 commented Aug 30, 2018

Try with some variation of this code (by H. Stacey)

from matplotlib import pyplot as plt
from matplotlib import transforms as mtransforms
from mpl_toolkits.axes_grid.parasite_axes import SubplotHost


class Wavelength2FreqTransform(mtransforms.Transform):
        input_dims = 1
        output_dims = 1
        is_separable = False
        has_inverse = True

        def __init__(self):
            mtransforms.Transform.__init__(self)

        def transform_non_affine(self, wl):
            return ((wl*un.um).to(un.GHz, equivalencies=un.spectral()).value)/(1+z)

        def inverted(self):
            return Freq2WavelengthTransform()

   class Freq2WavelengthTransform(Wavelength2FreqTransform):
        input_dims = 1
        output_dims = 1
        is_separable = False
        has_inverse = True

        def __init__(self):
            mtransforms.Transform.__init__(self)

        def transform_non_affine(self, fr):
            return ((fr*un.GHz).to(un.um, equivalencies=un.spectral()).value)

        def inverted(self):
            return Wavelength2FreqTransform()

    aux_trans = mtransforms.BlendedGenericTransform(Wavelength2FreqTransform(), mtransforms.IdentityTransform())
    fig = plt.figure(figsize=(8,6))
    ax_um = SubplotHost(fig, 1,1,1)
    fig.add_subplot(ax_um)
    ax_um.set_xlabel(r'Rest wav ($\mu$m)')

   ax_GHz = ax_um.twin(aux_trans)
   ax_GHz.set_xlabel('Observed freq (GHz)')
   ax_GHz.set_viewlim_mode('transform')
   ax_GHz.axis['right'].toggle(ticklabels=False)

   ax_GHz.set_xscale('log')
   ax_GHz.set_yscale('log')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ToDo
Projects
None yet
Development

No branches or pull requests

1 participant