Ejemplo n.º 1
0
 def makePowerSpectrum(
         self, freqs: np.array, power: np.array, sm_power: np.array,
         band_max_power: float, freq_at_band_max_power: float,
         max_freq: int = 50, theta_range: tuple = [6, 12],
         ax: matplotlib.axes = None, **kwargs) -> matplotlib.axes:
     # downsample frequencies and power
     freqs = freqs[0::50]
     power = power[0::50]
     sm_power = sm_power[0::50]
     if ax is None:
         fig = plt.figure()
         ax = fig.add_subplot(111)
     ax.plot(freqs, power, alpha=0.5, color=[0.8627, 0.8627, 0.8627])
     ax.plot(freqs, sm_power)
     ax.set_xlim(0, max_freq)
     ylim = [0, band_max_power / 0.8]
     if 'ylim' in kwargs:
         ylim = kwargs['ylim']
     ax.set_ylim(ylim)
     ax.set_ylabel('Power')
     ax.set_xlabel('Frequency')
     ax.text(
         x=theta_range[1] / 0.9, y=band_max_power,
         s=str(freq_at_band_max_power)[0:4], fontsize=20)
     from matplotlib.patches import Rectangle
     r = Rectangle((
         theta_range[0], 0), width=np.diff(theta_range)[0],
         height=np.diff(ax.get_ylim())[0], alpha=0.25, color='r', ec='none')
     ax.add_patch(r)
     return ax
Ejemplo n.º 2
0
def highlight_base(
    pos_highlight: int, seq: SeqRecord, ax: mpl.axes, passed_filter=True
) -> mpl.axes:
    """Highlight the area around a peak with a rectangle."""

    peaks = seq.annotations["peak positions"]
    peak = peaks[pos_highlight - 1]

    xmin, xmax = ax.get_xlim()
    if not xmin <= peak < xmax:
        raise ValueError("peak not within plot bounds")

    if pos_highlight == 1:
        xmin = -0.5
    else:
        xmin = 0.5 * (peaks[pos_highlight - 1] + peaks[pos_highlight - 2])

    if pos_highlight == len(peaks):
        xmax = -0.5
    else:
        xmax = 0.5 * (peaks[pos_highlight - 1] + peaks[pos_highlight])
    ymin, ymax = ax.get_ylim()

    if passed_filter:
        fcolor = "yellow"
    else:
        fcolor = "grey"
    rec = mpl.patches.Rectangle(
        (xmin, ymin),
        (xmax - xmin),
        (ymax - ymin),
        edgecolor="none",
        facecolor=fcolor,
        alpha=0.3,
    )
    ax.add_patch(rec)
    return ax