Skip to content

Commit e1e7c48

Browse files
committed
Figure update: trendlines,axis label
1 parent 5430b6e commit e1e7c48

File tree

3 files changed

+49
-53
lines changed

3 files changed

+49
-53
lines changed

scripts/figures/plot_fig2.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ def fig_02d_01(save_path, plot=False, all_versions=False, plot_average_ribbon_sy
270270
ax[0].set_xlim(xmin, xmax)
271271
lower_y, upper_y = literature_reference_values("SGN")
272272
ax[0].hlines([lower_y, upper_y], xmin, xmax)
273-
ax[0].text(1.1, (lower_y + upper_y) // 2, "literature", color="C0", fontsize=main_tick_size, ha="left")
273+
ax[0].text(1., lower_y + (upper_y - lower_y) * 0.2, "literature",
274+
color="C0", fontsize=main_tick_size, ha="center")
274275
ax[0].fill_between([xmin, xmax], lower_y, upper_y, color="C0", alpha=0.05, interpolate=True)
275276

276277
ylim0 = 600
@@ -291,7 +292,7 @@ def fig_02d_01(save_path, plot=False, all_versions=False, plot_average_ribbon_sy
291292
lower_y, upper_y = literature_reference_values("IHC")
292293
ax[1].set_xlim(xmin, xmax)
293294
ax[1].hlines([lower_y, upper_y], xmin, xmax)
294-
ax[1].text(1.1, (lower_y + upper_y) // 2, "literature", color="C0", fontsize=main_tick_size, ha="left")
295+
# ax[1].text(1.1, (lower_y + upper_y) // 2, "literature", color="C0", fontsize=main_tick_size, ha="left")
295296
ax[1].fill_between([xmin, xmax], lower_y, upper_y, color="C0", alpha=0.05, interpolate=True)
296297

297298
if plot_average_ribbon_synapses:
@@ -312,7 +313,7 @@ def fig_02d_01(save_path, plot=False, all_versions=False, plot_average_ribbon_sy
312313
lower_y, upper_y = literature_reference_values("synapse")
313314
ax[2].set_xlim(xmin, xmax)
314315
ax[2].hlines([lower_y, upper_y], xmin, xmax)
315-
ax[2].text(1.1, (lower_y + upper_y) // 2, "literature", color="C0", fontsize=main_tick_size, ha="left")
316+
# ax[2].text(1.1, (lower_y + upper_y) // 2, "literature", color="C0", fontsize=main_tick_size, ha="left")
316317
ax[2].fill_between([xmin, xmax], lower_y, upper_y, color="C0", alpha=0.05, interpolate=True)
317318

318319
plt.tight_layout()

scripts/figures/plot_fig4.py

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,17 @@ def fig_04c(chreef_data, save_path, plot=False, plot_by_side=False, use_alias=Tr
136136

137137
main_label_size = 20
138138
sub_label_size = 16
139-
main_tick_size = 12
139+
main_tick_size = 16
140140
legendsize = 16
141141

142142
if plot_by_side:
143-
plt.scatter(x, sgns_left, label="SGN count (Left)", marker="o", s=80)
144-
plt.scatter(x, sgns_right, label="SGN count (Right)", marker="x", s=80)
143+
plt.scatter(x, sgns_left, label="Left", marker="o", s=80)
144+
plt.scatter(x, sgns_right, label="Right", marker="x", s=80)
145145
else:
146146
plt.scatter(x, sgns, label="SGN count", marker="o", s=80)
147147

148148
# Labels and formatting
149149
plt.xticks(x, alias, fontsize=sub_label_size)
150-
plt.xlabel("Cochlea", fontsize=main_label_size)
151150
plt.yticks(fontsize=main_tick_size)
152151
plt.ylabel("SGN count per cochlea", fontsize=main_label_size)
153152
plt.ylim(4000, 13800)
@@ -224,7 +223,7 @@ def fig_04d(chreef_data, save_path, plot=False, plot_by_side=False, intensity=Fa
224223

225224
main_label_size = 20
226225
sub_label_size = 16
227-
main_tick_size = 12
226+
main_tick_size = 16
228227
legendsize = 16
229228

230229
label = "Intensity" if intensity else "Transduction efficiency"
@@ -237,7 +236,6 @@ def fig_04d(chreef_data, save_path, plot=False, plot_by_side=False, intensity=Fa
237236

238237
# Labels and formatting
239238
plt.xticks(x, alias, fontsize=sub_label_size)
240-
plt.xlabel("Cochlea", fontsize=main_label_size)
241239
plt.yticks(fontsize=main_tick_size)
242240
plt.ylabel(label, fontsize=main_label_size)
243241
plt.legend(loc="best", fontsize=sub_label_size)
@@ -262,8 +260,7 @@ def fig_04d(chreef_data, save_path, plot=False, plot_by_side=False, intensity=Fa
262260
plt.close()
263261

264262

265-
def fig_04e(chreef_data, save_path, plot, intensity=False, gerbil=False, use_alias=True, trendlines=False,
266-
trendline_fit="linear_regression"):
263+
def fig_04e(chreef_data, save_path, plot, intensity=False, gerbil=False, use_alias=True, trendlines=False):
267264

268265
result = {"cochlea": [], "octave_band": [], "value": []}
269266
for name, values in chreef_data.items():
@@ -312,6 +309,8 @@ def fig_04e(chreef_data, save_path, plot, intensity=False, gerbil=False, use_ali
312309
cochleas = sorted({name_lr[:-1] for name_lr in result["cochlea"].unique()})
313310
colors = plt.cm.tab10.colors # pick a colormap
314311
color_map = {cochlea: colors[i % len(colors)] for i, cochlea in enumerate(cochleas)}
312+
if len(cochleas) == 1:
313+
color_map = {"L": colors[0], "R": colors[1]}
315314

316315
# Track which cochlea names we have already added to the legend
317316
legend_added = set()
@@ -323,16 +322,24 @@ def fig_04e(chreef_data, save_path, plot, intensity=False, gerbil=False, use_ali
323322

324323
for name_lr, grp in result.groupby("cochlea"):
325324
name, side = name_lr[:-1], name_lr[-1]
325+
if len(cochleas) == 1:
326+
label_name = name_lr
327+
color = color_map[side]
328+
else:
329+
label_name = name
330+
color = color_map[name]
331+
326332
x_positions = grp["x_pos"] + offset_map[side]
327333
ax.scatter(
328334
x_positions,
329335
grp["value"],
330-
label=name if name not in legend_added else None,
336+
label=label_name if label_name not in legend_added else None,
331337
s=60,
332338
alpha=0.8,
333339
marker="o" if side == "L" else "x",
334-
color=color_map[name]
340+
color=color,
335341
)
342+
336343
if name not in legend_added:
337344
legend_added.add(name)
338345

@@ -361,43 +368,32 @@ def get_trendline_values(trend_dict, side):
361368
# Trendline left
362369
x_sorted, y_sorted = get_trendline_values(trend_dict, "L")
363370

364-
if trendline_fit == "linear_regression":
365-
# linear regression
366-
coeffs = np.polyfit(x_sorted, y_sorted, 1)
367-
poly_fn = np.poly1d(coeffs)
368-
369-
ax.plot(
370-
x_sorted,
371-
poly_fn(x_sorted),
372-
linestyle="dotted",
373-
color="red",
374-
alpha=0.7
375-
)
376-
377-
# if trendline_fit == "LOWESS":
378-
# # Fit LOWESS curve, using statsmodels.nonparametric.smoothers_lowess
379-
# lowess_fit = lowess(y_sorted, x_sorted, frac=0.4) # frac for smoothness (0.2 = wiggly, 0.6 = smoother)
380-
# x_fit, y_fit = lowess_fit[:, 0], lowess_fit[:, 1]
381-
# ax.plot(x_fit, y_fit, linestyle="dotted", color="red", alpha=0.7)
382-
383-
# Trendline right
384-
x_sorted, y_sorted = get_trendline_values(trend_dict, "R")
371+
trend_l, = ax.plot(
372+
x_sorted,
373+
y_sorted,
374+
linestyle="dotted",
375+
color="grey",
376+
alpha=0.7
377+
)
385378

386-
if trendline_fit == "linear_regression":
387-
coeffs = np.polyfit(x_sorted, y_sorted, 1)
388-
poly_fn = np.poly1d(coeffs)
389-
ax.plot(
390-
x_sorted,
391-
poly_fn(x_sorted),
392-
linestyle="dashed",
393-
color="blue",
394-
alpha=0.7
395-
)
396-
# if trendline_fit == "LOWESS":
397-
# # Fit LOWESS curve, using statsmodels.nonparametric.smoothers_lowess
398-
# lowess_fit = lowess(y_sorted, x_sorted, frac=0.4) # frac for smoothness (0.2 = wiggly, 0.6 = smoother)
399-
# x_fit, y_fit = lowess_fit[:, 0], lowess_fit[:, 1]
400-
# ax.plot(x_fit, y_fit, linestyle="dashed", color="blue", alpha=0.7)
379+
x_sorted, y_sorted = get_trendline_values(trend_dict, "R")
380+
trend_r, = ax.plot(
381+
x_sorted,
382+
y_sorted,
383+
linestyle="dashed",
384+
color="grey",
385+
alpha=0.7
386+
)
387+
trendline_legend = ax.legend(handles=[trend_l, trend_r], loc='lower center')
388+
trendline_legend = ax.legend(
389+
handles=[trend_l, trend_r],
390+
labels=["Left", "Right"],
391+
loc="lower center",
392+
fontsize=legend_size,
393+
title="Trendlines"
394+
)
395+
# Add the legend manually to the Axes.
396+
ax.add_artist(trendline_legend)
401397

402398
# Create combined tick positions & labels
403399
main_ticks = range(len(bin_labels))
@@ -423,6 +419,7 @@ def get_trendline_values(trend_dict, side):
423419
ax.set_title("Transduction efficiency per octave band (Left/Right)")
424420

425421
ax.legend(title="Cochlea", fontsize=legend_size)
422+
426423
plt.tight_layout()
427424

428425
if ".png" in save_path:
@@ -471,7 +468,7 @@ def main():
471468

472469
fig_04e(chreef_data,
473470
save_path=os.path.join(args.figure_dir, f"fig_04e_transduction.{FILE_EXTENSION}"),
474-
plot=args.plot, use_alias=use_alias, trendlines=False)
471+
plot=args.plot, use_alias=use_alias, trendlines=True)
475472
fig_04e(chreef_data,
476473
save_path=os.path.join(args.figure_dir, f"fig_04e_intensity.{FILE_EXTENSION}"),
477474
plot=args.plot, intensity=True, use_alias=use_alias)

scripts/figures/plot_fig6.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def fig_06b(save_path, plot=False):
5959
ax[0].set_xlim(xmin, xmax)
6060
lower_y, upper_y = literature_reference_values_gerbil("SGN")
6161
ax[0].hlines([lower_y, upper_y], xmin, xmax)
62-
ax[0].text(1, upper_y + 100, "literature reference", color='C0', fontsize=main_tick_size, ha="center")
62+
ax[0].text(1, upper_y - 2000, "literature", color='C0', fontsize=main_tick_size, ha="center")
6363
ax[0].fill_between([xmin, xmax], lower_y, upper_y, color='C0', alpha=0.05, interpolate=True)
6464

6565
ylim0 = 900
@@ -79,7 +79,6 @@ def fig_06b(save_path, plot=False):
7979
ax[1].set_xlim(xmin, xmax)
8080
lower_y, upper_y = literature_reference_values_gerbil("IHC")
8181
ax[1].hlines([lower_y, upper_y], xmin, xmax)
82-
ax[1].text(1, upper_y + 10, "literature reference", color='C0', fontsize=main_tick_size, ha="center")
8382
ax[1].fill_between([xmin, xmax], lower_y, upper_y, color='C0', alpha=0.05, interpolate=True)
8483

8584
ribbon_synapse_counts = _load_ribbon_synapse_counts()
@@ -100,7 +99,6 @@ def fig_06b(save_path, plot=False):
10099
lower_y, upper_y = literature_reference_values_gerbil("synapse")
101100
ax[2].set_xlim(xmin, xmax)
102101
ax[2].hlines([lower_y, upper_y], xmin, xmax)
103-
ax[2].text(1.1, (lower_y + upper_y) // 2, "literature", color="C0", fontsize=main_tick_size, ha="left")
104102
ax[2].fill_between([xmin, xmax], lower_y, upper_y, color="C0", alpha=0.05, interpolate=True)
105103

106104
plt.tight_layout()

0 commit comments

Comments
 (0)