diff --git a/code/chirpdetection.py b/code/chirpdetection.py index b694a63..cbc5e25 100755 --- a/code/chirpdetection.py +++ b/code/chirpdetection.py @@ -198,7 +198,7 @@ class ChirpPlotBuffer: for chirp in chirps: ax0.scatter( chirp, np.median(self.frequency), c=ps.red, marker=".", - edgecolors=ps.red, + edgecolors=ps.black, facecolors=ps.red, zorder=10, s=70, @@ -226,7 +226,7 @@ class ChirpPlotBuffer: ax4.scatter( (self.time)[self.baseline_peaks], (self.baseline_envelope*waveform_scaler)[self.baseline_peaks], - edgecolors=ps.red, + edgecolors=ps.black, facecolors=ps.red, zorder=10, marker=".", @@ -240,7 +240,7 @@ class ChirpPlotBuffer: ax5.scatter( (self.time)[self.search_peaks], (self.search_envelope*waveform_scaler)[self.search_peaks], - edgecolors=ps.red, + edgecolors=ps.black, facecolors=ps.red, zorder=10, marker=".", @@ -254,7 +254,7 @@ class ChirpPlotBuffer: ax6.scatter( self.frequency_time[self.frequency_peaks], self.frequency_filtered[self.frequency_peaks], - edgecolors=ps.red, + edgecolors=ps.black, facecolors=ps.red, zorder=10, marker=".", diff --git a/code/modules/plotstyle.py b/code/modules/plotstyle.py index 32af4d2..d5b9557 100644 --- a/code/modules/plotstyle.py +++ b/code/modules/plotstyle.py @@ -26,14 +26,14 @@ def PlotStyle() -> None: yellow = "#f9d67f" orange = "#faa472" maroon = "#eb8486" - red = "#f37588" + red = "#e0e4f7" purple = "#d89bf7" pink = "#f59edb" lavender = "#b4befe" - gblue1 = "#89b4fa" - gblue2 = "#89dceb" - gblue3 = "#a6e3a1" - g = "#76a0fa" + gblue1 = "#f37588" + gblue2 = "#faa472" + gblue3 = "#f9d67f" + g = "#f3626c" @classmethod def lims(cls, track1, track2): @@ -230,7 +230,7 @@ def PlotStyle() -> None: plt.rc("legend", fontsize=SMALL_SIZE) # legend fontsize plt.rc("figure", titlesize=BIGGER_SIZE) # fontsize of the figure title - plt.rcParams["image.cmap"] = "cmo.haline" + plt.rcParams["image.cmap"] = "cmo.thermal" plt.rcParams["axes.xmargin"] = 0.05 plt.rcParams["axes.ymargin"] = 0.1 plt.rcParams["axes.titlelocation"] = "left" diff --git a/code/modules/plotstyle1.py b/code/modules/plotstyle1.py new file mode 100644 index 0000000..32af4d2 --- /dev/null +++ b/code/modules/plotstyle1.py @@ -0,0 +1,407 @@ +import cmocean as cmo +import matplotlib.pyplot as plt +import numpy as np +from cycler import cycler +from matplotlib.colors import ListedColormap + + +def PlotStyle() -> None: + class style: + + # lightcmap = cmocean.tools.lighten(cmocean.cm.haline, 0.8) + + # units + cm = 1 / 2.54 + mm = 1 / 25.4 + + # colors + black = "#111116" + white = "#e0e4f7" + gray = "#6c6e7d" + blue = "#89b4fa" + sapphire = "#74c7ec" + sky = "#89dceb" + teal = "#94e2d5" + green = "#a6e3a1" + yellow = "#f9d67f" + orange = "#faa472" + maroon = "#eb8486" + red = "#f37588" + purple = "#d89bf7" + pink = "#f59edb" + lavender = "#b4befe" + gblue1 = "#89b4fa" + gblue2 = "#89dceb" + gblue3 = "#a6e3a1" + g = "#76a0fa" + + @classmethod + def lims(cls, track1, track2): + """Helper function to get frequency y axis limits from two + fundamental frequency tracks. + + Args: + track1 (array): First track + track2 (array): Second track + start (int): Index for first value to be plotted + stop (int): Index for second value to be plotted + padding (int): Padding for the upper and lower limit + + Returns: + lower (float): lower limit + upper (float): upper limit + + """ + allfunds_tmp = ( + np.concatenate( + [ + track1, + track2, + ] + ) + .ravel() + .tolist() + ) + lower = np.min(allfunds_tmp) + upper = np.max(allfunds_tmp) + return lower, upper + + @classmethod + def circled_annotation(cls, text, axis, xpos, ypos, padding=0.25): + axis.text( + xpos, + ypos, + text, + ha="center", + va="center", + zorder=1000, + bbox=dict( + boxstyle=f"circle, pad={padding}", fc="white", ec="black", lw=1 + ), + ) + + @classmethod + def fade_cmap(cls, cmap): + + my_cmap = cmap(np.arange(cmap.N)) + my_cmap[:, -1] = np.linspace(0, 1, cmap.N) + my_cmap = ListedColormap(my_cmap) + + return my_cmap + + @classmethod + def hide_ax(cls, ax): + ax.xaxis.set_visible(False) + plt.setp(ax.spines.values(), visible=False) + ax.tick_params(left=False, labelleft=False) + ax.patch.set_visible(False) + + @classmethod + def hide_xax(cls, ax): + ax.xaxis.set_visible(False) + ax.spines["bottom"].set_visible(False) + + @classmethod + def hide_yax(cls, ax): + ax.yaxis.set_visible(False) + ax.spines["left"].set_visible(False) + + @classmethod + def set_boxplot_color(cls, bp, color): + plt.setp(bp["boxes"], color=color) + plt.setp(bp["whiskers"], color=white) + plt.setp(bp["caps"], color=white) + plt.setp(bp["medians"], color=black) + + @classmethod + def label_subplots(cls, labels, axes, fig): + for axis, label in zip(axes, labels): + X = axis.get_position().x0 + Y = axis.get_position().y1 + fig.text(X, Y, label, weight="bold") + + @classmethod + def letter_subplots( + cls, axes=None, letters=None, xoffset=-0.1, yoffset=1.0, **kwargs + ): + """Add letters to the corners of subplots (panels). By default each axis is + given an uppercase bold letter label placed in the upper-left corner. + Args + axes : list of pyplot ax objects. default plt.gcf().axes. + letters : list of strings to use as labels, default ["A", "B", "C", ...] + xoffset, yoffset : positions of each label relative to plot frame + (default -0.1,1.0 = upper left margin). Can also be a list of + offsets, in which case it should be the same length as the number of + axes. + Other keyword arguments will be passed to annotate() when panel letters + are added. + Returns: + list of strings for each label added to the axes + Examples: + Defaults: + >>> fig, axes = plt.subplots(1,3) + >>> letter_subplots() # boldfaced A, B, C + + Common labeling schemes inferred from the first letter: + >>> fig, axes = plt.subplots(1,4) + # panels labeled (a), (b), (c), (d) + >>> letter_subplots(letters='(a)') + Fully custom lettering: + >>> fig, axes = plt.subplots(2,1) + >>> letter_subplots(axes, letters=['(a.1)', '(b.2)'], fontweight='normal') + Per-axis offsets: + >>> fig, axes = plt.subplots(1,2) + >>> letter_subplots(axes, xoffset=[-0.1, -0.15]) + + Matrix of axes: + >>> fig, axes = plt.subplots(2,2, sharex=True, sharey=True) + # fig.axes is a list when axes is a 2x2 matrix + >>> letter_subplots(fig.axes) + """ + + # get axes: + if axes is None: + axes = plt.gcf().axes + # handle single axes: + try: + iter(axes) + except TypeError: + axes = [axes] + + # set up letter defaults (and corresponding fontweight): + fontweight = "bold" + ulets = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ"[: len(axes)]) + llets = list("abcdefghijklmnopqrstuvwxyz"[: len(axes)]) + if letters is None or letters == "A": + letters = ulets + elif letters == "(a)": + letters = ["({})".format(lett) for lett in llets] + fontweight = "normal" + elif letters == "(A)": + letters = ["({})".format(lett) for lett in ulets] + fontweight = "normal" + elif letters in ("lower", "lowercase", "a"): + letters = llets + + # make sure there are x and y offsets for each ax in axes: + if isinstance(xoffset, (int, float)): + xoffset = [xoffset] * len(axes) + else: + assert len(xoffset) == len(axes) + if isinstance(yoffset, (int, float)): + yoffset = [yoffset] * len(axes) + else: + assert len(yoffset) == len(axes) + + # defaults for annotate (kwargs is second so it can overwrite these defaults): + my_defaults = dict( + fontweight=fontweight, + fontsize="large", + ha="center", + va="center", + xycoords="axes fraction", + annotation_clip=False, + ) + kwargs = dict(list(my_defaults.items()) + list(kwargs.items())) + + list_txts = [] + for ax, lbl, xoff, yoff in zip(axes, letters, xoffset, yoffset): + t = ax.annotate(lbl, xy=(xoff, yoff), **kwargs) + list_txts.append(t) + return list_txts + + pass + + # rcparams text setup + SMALL_SIZE = 12 + MEDIUM_SIZE = 14 + BIGGER_SIZE = 16 + black = "#111116" + white = "#e0e4f7" + gray = "#6c6e7d" + dark_gray = "#2a2a32" + + # rcparams + plt.rc("font", size=MEDIUM_SIZE) # controls default text sizes + plt.rc("axes", titlesize=MEDIUM_SIZE) # fontsize of the axes title + plt.rc("axes", labelsize=MEDIUM_SIZE) # fontsize of the x and y labels + plt.rc("xtick", labelsize=SMALL_SIZE) # fontsize of the tick labels + plt.rc("ytick", labelsize=SMALL_SIZE) # fontsize of the tick labels + plt.rc("legend", fontsize=SMALL_SIZE) # legend fontsize + plt.rc("figure", titlesize=BIGGER_SIZE) # fontsize of the figure title + + plt.rcParams["image.cmap"] = "cmo.haline" + plt.rcParams["axes.xmargin"] = 0.05 + plt.rcParams["axes.ymargin"] = 0.1 + plt.rcParams["axes.titlelocation"] = "left" + plt.rcParams["axes.titlesize"] = BIGGER_SIZE + # plt.rcParams["axes.titlepad"] = -10 + plt.rcParams["legend.frameon"] = False + plt.rcParams["legend.loc"] = "best" + plt.rcParams["legend.borderpad"] = 0.4 + plt.rcParams["legend.facecolor"] = black + plt.rcParams["legend.edgecolor"] = black + plt.rcParams["legend.framealpha"] = 0.7 + plt.rcParams["legend.borderaxespad"] = 0.5 + plt.rcParams["legend.fancybox"] = False + + # # specify the custom font to use + # plt.rcParams["font.family"] = "sans-serif" + # plt.rcParams["font.sans-serif"] = "Helvetica Now Text" + + # dark mode modifications + plt.rcParams["boxplot.flierprops.color"] = white + plt.rcParams["boxplot.flierprops.markeredgecolor"] = gray + plt.rcParams["boxplot.boxprops.color"] = gray + plt.rcParams["boxplot.whiskerprops.color"] = gray + plt.rcParams["boxplot.capprops.color"] = gray + plt.rcParams["boxplot.medianprops.color"] = black + plt.rcParams["text.color"] = white + plt.rcParams["axes.facecolor"] = black # axes background color + plt.rcParams["axes.edgecolor"] = white # axes edge color + # plt.rcParams["axes.grid"] = True # display grid or not + # plt.rcParams["axes.grid.axis"] = "y" # which axis the grid is applied to + plt.rcParams["axes.labelcolor"] = white + plt.rcParams["axes.axisbelow"] = True # draw axis gridlines and ticks: + plt.rcParams["axes.spines.left"] = True # display axis spines + plt.rcParams["axes.spines.bottom"] = True + plt.rcParams["axes.spines.top"] = False + plt.rcParams["axes.spines.right"] = False + plt.rcParams["axes.prop_cycle"] = cycler( + "color", + [ + "#b4befe", + "#89b4fa", + "#74c7ec", + "#89dceb", + "#94e2d5", + "#a6e3a1", + "#f9e2af", + "#fab387", + "#eba0ac", + "#f38ba8", + "#cba6f7", + "#f5c2e7", + ], + ) + plt.rcParams["xtick.color"] = white # color of the ticks + plt.rcParams["ytick.color"] = white # color of the ticks + plt.rcParams["grid.color"] = white # grid color + plt.rcParams["figure.facecolor"] = black # figure face color + plt.rcParams["figure.edgecolor"] = black # figure edge color + plt.rcParams["savefig.facecolor"] = black # figure face color when saving + + return style + + +if __name__ == "__main__": + + s = PlotStyle() + + import matplotlib.cbook as cbook + import matplotlib.cm as cm + import matplotlib.pyplot as plt + from matplotlib.patches import PathPatch + from matplotlib.path import Path + + # Fixing random state for reproducibility + np.random.seed(19680801) + + delta = 0.025 + x = y = np.arange(-3.0, 3.0, delta) + X, Y = np.meshgrid(x, y) + Z1 = np.exp(-(X**2) - Y**2) + Z2 = np.exp(-((X - 1) ** 2) - (Y - 1) ** 2) + Z = (Z1 - Z2) * 2 + + fig1, ax = plt.subplots() + im = ax.imshow( + Z, + interpolation="bilinear", + cmap=cm.RdYlGn, + origin="lower", + extent=[-3, 3, -3, 3], + vmax=abs(Z).max(), + vmin=-abs(Z).max(), + ) + + plt.show() + + fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(9, 4)) + + # Fixing random state for reproducibility + np.random.seed(19680801) + + # generate some random test data + all_data = [np.random.normal(0, std, 100) for std in range(6, 10)] + + # plot violin plot + axs[0].violinplot(all_data, showmeans=False, showmedians=True) + axs[0].set_title("Violin plot") + + # plot box plot + axs[1].boxplot(all_data) + axs[1].set_title("Box plot") + + # adding horizontal grid lines + for ax in axs: + ax.yaxis.grid(True) + ax.set_xticks( + [y + 1 for y in range(len(all_data))], labels=["x1", "x2", "x3", "x4"] + ) + ax.set_xlabel("Four separate samples") + ax.set_ylabel("Observed values") + + plt.show() + + # Fixing random state for reproducibility + np.random.seed(19680801) + + # Compute pie slices + N = 20 + theta = np.linspace(0.0, 2 * np.pi, N, endpoint=False) + radii = 10 * np.random.rand(N) + width = np.pi / 4 * np.random.rand(N) + colors = cmo.cm.haline(radii / 10.0) + + ax = plt.subplot(projection="polar") + ax.bar(theta, radii, width=width, bottom=0.0, color=colors, alpha=0.5) + + plt.show() + + methods = [ + None, + "none", + "nearest", + "bilinear", + "bicubic", + "spline16", + "spline36", + "hanning", + "hamming", + "hermite", + "kaiser", + "quadric", + "catrom", + "gaussian", + "bessel", + "mitchell", + "sinc", + "lanczos", + ] + + # Fixing random state for reproducibility + np.random.seed(19680801) + + grid = np.random.rand(4, 4) + + fig, axs = plt.subplots( + nrows=3, ncols=6, figsize=(9, 6), subplot_kw={"xticks": [], "yticks": []} + ) + + for ax, interp_method in zip(axs.flat, methods): + ax.imshow(grid, interpolation=interp_method) + ax.set_title(str(interp_method)) + + plt.tight_layout() + plt.show() diff --git a/code/plot_chirp_size.py b/code/plot_chirp_size.py index bfaf170..962e00e 100644 --- a/code/plot_chirp_size.py +++ b/code/plot_chirp_size.py @@ -262,7 +262,7 @@ def main(datapath: str): stat = wilcoxon(chirps_winner, chirps_loser) print(stat) - winner_color = ps.gblue3 + winner_color = ps.gblue2 loser_color = ps.gblue1 bplot1 = ax1.boxplot(chirps_winner, positions=[ diff --git a/code/plot_event_timeline.py b/code/plot_event_timeline.py index ed663c4..fc7c6d8 100644 --- a/code/plot_event_timeline.py +++ b/code/plot_event_timeline.py @@ -48,16 +48,16 @@ def main(datapath: str): fish1 = (bh.chirps[bh.chirps_ids == fish1_id] / 60) / 60 fish2 = (bh.chirps[bh.chirps_ids == fish2_id] / 60) / 60 fish1_color = ps.gblue1 - fish2_color = ps.gblue3 + fish2_color = ps.gblue2 fig, ax = plt.subplots(5, 1, figsize=( 21*ps.cm, 10*ps.cm), height_ratios=[0.5, 0.5, 0.5, 0.2, 6], sharex=True) # marker size s = 80 ax[0].scatter(physical_contact, np.ones( - len(physical_contact)), color=ps.red, marker='|', s=s) + len(physical_contact)), color=ps.gray, marker='|', s=s) ax[1].scatter(chasing_onset, np.ones(len(chasing_onset)), - color=ps.purple, marker='|', s=s) + color=ps.gray, marker='|', s=s) ax[2].scatter(fish1, np.ones(len(fish1))-0.25, color=fish1_color, marker='|', s=s) ax[2].scatter(fish2, np.zeros(len(fish2))+0.25, diff --git a/code/plot_kdes.py b/code/plot_kdes.py index efbd5c0..9c27002 100644 --- a/code/plot_kdes.py +++ b/code/plot_kdes.py @@ -276,7 +276,7 @@ def main(dataroot): # loser_physicals[-1], kde_time, kernel_width) ax[i].plot(kde_time, loser_offsets_conv / - len(offsets), lw=2, zorder=100) + len(offsets), lw=2, zorder=100, c=ps.gblue1) ax[i].fill_between( kde_time, diff --git a/poster/figs/algorithm.pdf b/poster/figs/algorithm.pdf index ad72921..50a12c3 100644 Binary files a/poster/figs/algorithm.pdf and b/poster/figs/algorithm.pdf differ diff --git a/poster/figs/algorithm1.pdf b/poster/figs/algorithm1.pdf index 92d0482..2f47746 100644 Binary files a/poster/figs/algorithm1.pdf and b/poster/figs/algorithm1.pdf differ diff --git a/poster/figs/chirps_winner_loser.pdf b/poster/figs/chirps_winner_loser.pdf index 4c40103..88aba99 100644 Binary files a/poster/figs/chirps_winner_loser.pdf and b/poster/figs/chirps_winner_loser.pdf differ diff --git a/poster/figs/introplot.pdf b/poster/figs/introplot.pdf index 619182d..8f31f67 100644 Binary files a/poster/figs/introplot.pdf and b/poster/figs/introplot.pdf differ diff --git a/poster/figs/kde.pdf b/poster/figs/kde.pdf index ba87f34..cae4b43 100644 Binary files a/poster/figs/kde.pdf and b/poster/figs/kde.pdf differ diff --git a/poster/figs/timeline.pdf b/poster/figs/timeline.pdf index 9066e02..1430a58 100644 Binary files a/poster/figs/timeline.pdf and b/poster/figs/timeline.pdf differ