def test_scatter_correlation(): x = np.arange(100) _, ax = plt.subplots() ax = scatter_correlation(x, x, ax=ax) npt.assert_equal(len(ax.texts), 1) npt.assert_equal('$r$=1.000' in ax.texts[0].get_text(), True) # Ignore NaN: ax = scatter_correlation([0, 1, np.nan, 3], [0, 1, 2, 3]) npt.assert_equal('$r$=1.000' in ax.texts[0].get_text(), True) with pytest.raises(ValueError): scatter_correlation(np.arange(10), np.arange(11)) with pytest.raises(ValueError): scatter_correlation([1], [2])
plt.ylim(0, 60) # set plot labels and title plt.xlabel('Amplitude (uA) / Threshold (uA)') plt.ylabel('Brightness Rating') plt.title('Amplitude Modulation Brightness') ############################################################################### # Using Built-In Plotting Functionality # ----------------- # # Arguably the most important column is "freq". This is the current # amplitude of the different stimuli (single pulse, pulse trains, etc.) used # at threshold. # # We might be interested in seeing how the phosphene brightness varies as a function # of pulse frequency. We could either use Matplotlib to generate a scatter plot # or use pulse2percept's own visualization function: from pulse2percept.viz import scatter_correlation scatter_correlation(data.freq, data.brightness) ############################################################################### # :py:func:`~pulse2percept.viz.scatter_correlation` above generates a scatter # plot of the phosphene brightness as a function of pulse frequency, and performs # linear regression to calculate a correlation $r$ and a $p$ value. # As expected from the literature, now it becomes evident that phosphene # brightness is positively correlated with pulse frequency #
print(load_horsager2009(stim_types='single_pulse')) ############################################################################### # Plotting the data # ----------------- # # Arguably the most important column is "stim_amp". This is the current # amplitude of the different stimuli (single pulse, pulse trains, etc.) used # at threshold. # # We might be interested in seeing how threshold amplitude varies as a function # of pulse duration. We could either use Matplotlib to generate a scatter plot # or use pulse2percept's own visualization function: from pulse2percept.viz import scatter_correlation scatter_correlation(data.pulse_dur, data.stim_amp) ############################################################################### # :py:func:`~pulse2percept.viz.scatter_correlation` above generates a scatter # plot of the stimulus amplitude as a function of pulse duration, and performs # linear regression to calculate a correlation $r$ and a $p$ value. # As expected from the literature, now it becomes evident that stimulus # amplitude is negatively correlated with pulse duration (no matter the exact # stimulus used). # # Recreating the stimuli # ---------------------- # # To recreate the stimulus used to obtain a specific data point, we need to use # the values specified in the different columns of a particular row. #