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
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
def _draw_outer_border(ax: axes, xmin, xmax, ymin, ymax, **kwargs): """ Fill the right upper corner of a diagram, everything beyond (xmin, ymin). The following graphic shows the filled regions with dots: ↑ ymax +.............. |.............. ymin +.............. | ....... | ....... +-------+-----+-→ xmin xmax """ verts = [(xmin, ymin), (xmin, 0), (xmax, 0), (xmax, ymax), (0, ymax), (0, ymin)] return ax.add_patch(Polygon(np.array(verts), **kwargs))