adding plotstyle boxplots

This commit is contained in:
wendtalexander 2023-01-24 13:56:41 +01:00
parent 4e7bd40ea4
commit ea98a20a68
2 changed files with 27 additions and 20 deletions

View File

@ -108,9 +108,6 @@ def PlotStyle() -> None:
@classmethod @classmethod
def set_boxplot_color(cls, bp, color): def set_boxplot_color(cls, bp, color):
plt.setp(bp["boxes"], color=color) plt.setp(bp["boxes"], color=color)
plt.setp(bp["whiskers"], color=color)
plt.setp(bp["caps"], color=color)
plt.setp(bp["medians"], color=color)
@classmethod @classmethod
def label_subplots(cls, labels, axes, fig): def label_subplots(cls, labels, axes, fig):
@ -250,11 +247,11 @@ def PlotStyle() -> None:
# dark mode modifications # dark mode modifications
plt.rcParams["boxplot.flierprops.color"] = white plt.rcParams["boxplot.flierprops.color"] = white
plt.rcParams["boxplot.flierprops.markeredgecolor"] = gray plt.rcParams["boxplot.flierprops.markeredgecolor"] = white
plt.rcParams["boxplot.boxprops.color"] = gray plt.rcParams["boxplot.boxprops.color"] = gray
plt.rcParams["boxplot.whiskerprops.color"] = gray plt.rcParams["boxplot.whiskerprops.color"] = white
plt.rcParams["boxplot.capprops.color"] = gray plt.rcParams["boxplot.capprops.color"] = white
plt.rcParams["boxplot.medianprops.color"] = gray plt.rcParams["boxplot.medianprops.color"] = white
plt.rcParams["text.color"] = white plt.rcParams["text.color"] = white
plt.rcParams["axes.facecolor"] = black # axes background color plt.rcParams["axes.facecolor"] = black # axes background color
plt.rcParams["axes.edgecolor"] = gray # axes edge color plt.rcParams["axes.edgecolor"] = gray # axes edge color

View File

@ -1,9 +1,9 @@
import numpy as np import numpy as np
import os import os
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from thunderfish.powerspectrum import decibel from thunderfish.powerspectrum import decibel
from IPython import embed from IPython import embed
@ -19,11 +19,13 @@ logger = makeLogger(__name__)
def main(datapath: str): def main(datapath: str):
foldernames = [datapath + x + '/' for x in os.listdir(datapath) if os.path.isdir(datapath+x)] foldernames = [
path_to_csv = ('/').join(foldernames[0].split('/')[:-2]) + '/order_meta.csv' datapath + x + '/' for x in os.listdir(datapath) if os.path.isdir(datapath+x)]
path_to_csv = (
'/').join(foldernames[0].split('/')[:-2]) + '/order_meta.csv'
meta_id = read_csv(path_to_csv) meta_id = read_csv(path_to_csv)
meta_id['recording'] = meta_id['recording'].str[1:-1] meta_id['recording'] = meta_id['recording'].str[1:-1]
chirps_winner = [] chirps_winner = []
chirps_loser = [] chirps_loser = []
@ -61,27 +63,35 @@ def main(datapath: str):
chirps_winner.append(chirp_winner) chirps_winner.append(chirp_winner)
chirps_loser.append(chirp_loser) chirps_loser.append(chirp_loser)
fish1_id = all_fish_ids[0] fish1_id = all_fish_ids[0]
fish2_id = all_fish_ids[1] fish2_id = all_fish_ids[1]
print(winner_fish_id) print(winner_fish_id)
print(all_fish_ids) print(all_fish_ids)
fig, ax = plt.subplots() fig, ax = plt.subplots()
ax.boxplot([chirps_winner, chirps_loser], showfliers=False) bplot1 = ax.boxplot(chirps_winner, positions=[
ax.scatter(np.ones(len(chirps_winner)), chirps_winner, color='r') 1], showfliers=False, patch_artist=True)
ax.scatter(np.ones(len(chirps_loser))*2, chirps_loser, color='r') bplot2 = ax.boxplot(chirps_loser, positions=[
2], showfliers=False, patch_artist=True)
ax.scatter(np.ones(len(chirps_winner))*1.15, chirps_winner, color='r')
ax.scatter(np.ones(len(chirps_loser))*1.85, chirps_loser, color='r')
ax.set_xticklabels(['winner', 'loser']) ax.set_xticklabels(['winner', 'loser'])
for w, l in zip(chirps_winner, chirps_loser): for w, l in zip(chirps_winner, chirps_loser):
ax.plot([1,2], [w,l], color='r', alpha=0.5, linewidth=0.5) ax.plot([1.15, 1.85], [w, l], color='r', alpha=0.5, linewidth=0.5)
colors1 = ps.red
ps.set_boxplot_color(bplot1, colors1)
colors1 = ps.orange
ps.set_boxplot_color(bplot2, colors1)
ax.set_ylabel('Chirpscounts [n]') ax.set_ylabel('Chirpscounts [n]')
plt.show() plt.show()
if __name__ == '__main__': if __name__ == '__main__':
# Path to the data # Path to the data
datapath = '../data/mount_data/' datapath = '../data/mount_data/'
main(datapath) main(datapath)