views:

65

answers:

2

Trying to plot a spectrum, ie, velocity versus intensity, with lower x axis = velocity, on the upper twin axis = frequency

The relationship between them (doppler formula) is

f = (1-v/c)*f_0 

where f is the resulting frequency, v the velocity, c the speed of light, and f_0 the frequency at v=0, ie. the v_lsr.

I have tried to solve it by looking at http://matplotlib.sourceforge.net/examples/axes_grid/parasite_simple2.html , where it is solved by

pm_to_kms = 1./206265.*2300*3.085e18/3.15e7/1.e5
aux_trans = matplotlib.transforms.Affine2D().scale(pm_to_kms, 1.)
ax_pm = ax_kms.twin(aux_trans)
ax_pm.set_viewlim_mode("transform")

but my problem is that it is not a simple scaling law, but a linear function.

Anyone know how to solve this?

A: 

Your "linear function" is a "simple scaling law" (with an offset). Just replace the pm_to_kms definition with your function.

honk
well yes...so you mean that I do two transforms, one scaling and one translation?likekms_to_deltafreq = -f0/cdeltafreq_to_freq = f0matplotlib.transforms.Affine2D().scale(kms_to_deltafreq, 1.).translate(deltafreq_to_freq,1)ax_freq = ax_kms.twin(aux_trans)ax_freq.set_viewlim_mode("transform")??
+1  A: 

The solution I ended up using was:

ax_hz = ax_kms.twiny()
x_1, x_2 = ax_kms.get_xlim()
# i want the frequency in GHz so, divide by 1e9
ax_hz.set_xlim(calc_frequency(x_1,data.restfreq/1e9),calc_frequency(x_2,data.restfreq/1e9))

This works perfect, and much less complicated solution.

Cheers, Magnus