Ejemplo n.º 1
0
def plot_spectrum(spec: Spectrum,
                  freq_range: Tuple[u.Quantity],
                  table: Optional[Table] = None,
                  key: Optional[str] = None,
                  color_key: Optional[str] = None,
                  top: Optional[int] = None) -> Plot:
    """Plot spectrum.

    Args:
      spec: spectrum.
      freq_range: frequency range.
      table: optiona; table with values for markers.
      key: optiona; table column to extract markers.
      color_key: optional; column to use for marker colors.
      top: optional; only plot the top n values from table.
    """
    # Figure
    plt.close()
    fig = plt.figure(figsize=(5, 6))
    ax1 = fig.add_subplot(111)
    ax2 = ax1.twinx()

    # Plot spectrum
    ax1.plot(spec.spectral_axis, spec.intensity, 'b-')
    xlim = get_freq_lim(freq_range)
    ax1.set_xlim(*xlim)
    cent = spec.centroid(*freq_range)
    ax1.axvline(cent.value, ls='--', c='#6f6f6f')
    ax1.set_ylim(bottom=-0.001)
    ax1.set_ylabel(f'Intensity ({spec.intensity.unit:latex_inline})',
                   color='b')
    ax1.set_xlabel(f'Frequency ({spec.spectral_axis.unit:latex_inline})')

    # Spans
    ax1.axvspan(xlim[0], freq_range[0].value, facecolor='#6f6f6f', alpha=0.5)
    ax1.axvspan(freq_range[1].value, xlim[1], facecolor='#6f6f6f', alpha=0.5)

    # Plot table key
    if table is not None and key:
        plot_markers(ax2, table, key, top=top, color_key=color_key)

    return fig, ax1, ax2