def populate_figure(figure, wavefilter=lambda x: x, include_detail=False): wave, sample_rate = sine_wave(frequency=1000, num_periods=3) wave = wavefilter(wave) axes = figure.add_subplot(1, 1, 1) waveform(axes, wave, sample_rate) format_waveform_plot(figure) if include_detail: annotate_amplitude(axes, wave) axes.set_xticks([]) axes.set_xlabel('') axes.set_ylabel('')
def populate_figure(figure): axes = figure.add_subplot(1, 1, 1) # These are the default matplotlib colors, but we're hardcoding them # because they are mentioned explicitly in the accompanying text. for plot in plots: wave, sample_rate = sine_wave(frequency=1000, num_periods=2, phase_radians=np.radians( plot['phase_degrees'])) waveform(axes, wave, sample_rate, linestyle=plot['linestyle'], color=plot['color'], label=str(plot['phase_degrees']) + '°') format_waveform_plot(figure) axes.legend(loc='upper right') axes.set_yticks([])
def populate_waveform(axes): speed_of_sound = 343 length = 0.03 num_periods = int(length * frequency) base_wave, sample_rate = sine_wave(frequency=frequency, num_periods=num_periods) length_samples = int(length * sample_rate) wave = np.zeros(length_samples) for source in sources: distance = geometry.distance(source, listener) delay = distance / speed_of_sound wave += np.pad(base_wave / distance, int(sample_rate * delay), mode='constant')[:length_samples] axes.axvline(delay * 1000, linestyle='--', color='C1') waveform(axes, wave, sample_rate)
def populate_figure_wavesum(figure, wave1, wave2, sample_rate): axes = figure.add_subplot(1, 1, 1) wavesum = wave1 + wave2 waveform(axes, wave1, sample_rate, label='Wave 1') waveform(axes, wave2, sample_rate, label='Wave 2') waveform(axes, wavesum, sample_rate, label='Sum') format_waveform_plot(figure) axes.legend(loc='upper right') axes.set_xticks([]) axes.set_xlabel('Time') axes.set_ylim(-10, 10)
def populate_figure_wave(figure, wave, sample_rate): axes = figure.add_subplot(1, 1, 1) waveform(axes, wave, sample_rate) format_waveform_plot(figure) axes.set_yticks([])
def populate_figure(figure): waveform(figure.add_subplot(1, 1, 1), *noisy_sine_wave(num_periods=3)) format_waveform_plot(figure)
def populate_figure(figure): axes = figure.add_subplot(1, 1, 1) wave, sample_rate = sine_wave(frequency=1000, num_periods=2) waveform(axes, wave*1.41, sample_rate) format_waveform_plot(figure) axes.set_ylabel('Voltage (volts)')
def populate_figure(figure): axes = figure.add_subplot(1, 1, 1) wave, sample_rate = sine_wave(frequency=1000, num_periods=2) waveform(axes, wave*0.356, sample_rate) format_waveform_plot(figure) axes.set_ylabel('Sound pressure (Pa)')