예제 #1
0
 def makeXCorr(self, spk_times: np.array, ax: matplotlib.axes = None,
               **kwargs) -> matplotlib.axes:
     # spk_times in samples provided in seconds but convert to
     # ms for a more display friendly scale
     spk_times = spk_times / 3e4 * 1000.
     S = SpikeCalcsGeneric(spk_times)
     y = S.xcorr(spk_times)
     if ax is None:
         fig = plt.figure()
         ax = fig.add_subplot(111)
     ax.hist(
             y[y != 0], bins=201, range=[-500, 500],
             color='k', histtype='stepfilled')
     ax.set_xlim(-500, 500)
     ax.set_xticks((-500, 0, 500))
     ax.set_xticklabels('')
     ax.tick_params(
         axis='both', which='both', left=False, right=False,
         bottom=False, top=False)
     ax.set_yticklabels('')
     ax.spines['right'].set_visible(False)
     ax.spines['top'].set_visible(False)
     ax.spines['left'].set_visible(False)
     ax.xaxis.set_ticks_position('bottom')
     return ax
예제 #2
0
def plot_visit_durations(data: list, ax: Axes):
    """
    Plot the visit durations from the raw data.

    :param data: Raw data
    :param ax: Axes object in which to put the plot
    :return: None
    """
    # Histogram options
    min_visit_s = 30
    max_visit_s = 60 * 60 * 3
    nbins = 150

    # Regression line options
    fit_start = 6
    fit_stop = 144

    # Create histogram
    durations = get_visit_durations(data)
    n, bins, _ = ax.hist(durations, bins=linspace(min_visit_s, max_visit_s, nbins))

    # Create regression line
    bin_width = (bins[fit_stop - 1] - bins[fit_start]) / (fit_start - fit_stop)
    lin_fitting_bins = [b + bin_width / 2 for b in bins[fit_start:fit_stop]]
    lin_fitting_n = n[fit_start:fit_stop]
    [a, b] = polyfit(lin_fitting_bins, log(lin_fitting_n), 1, w=sqrt(lin_fitting_n))
    fitted_n = [exp(b + a * t) for t in lin_fitting_bins]
    regression_line_opts = {"linestyle": "--", "color": "black", "linewidth": 2}
    regression_label_text = "y={:.0f}exp({:.6f}*t)".format(exp(b), a)
    regression_label_coords = (max_visit_s * 0.6, max(n) * 0.5)
    ax.plot(lin_fitting_bins, fitted_n, **regression_line_opts)
    ax.text(*regression_label_coords, regression_label_text)

    # Label axes
    ax.set_xlabel("Varighet for visitt (s)")
    ax.set_ylabel("Andel visitter (vilkårlig)")
    ax.set_yscale("log")
예제 #3
0
def plot_histogram(data: List[np.float64], bins: int, axes: matplotlib.axes):
    axes.hist(x=data, bins=bins)
    axes.set_title('KDE plot')
    axes.set_xlabel('x')
    axes.set_ylabel('f')