Completedly overhauled fig_auditory_pathway.

Created new in-figure linked SVGs with clearer naming scheme.
Removed outdated image components.
This commit is contained in:
j-hartling
2026-01-28 16:46:38 +01:00
parent 3b757ac9e1
commit 0029566861
64 changed files with 5071 additions and 9627 deletions

View File

@@ -8,9 +8,12 @@ plt.rcParams['svg.fonttype'] = 'path'
plt.rc('text.latex', preamble=r'\usepackage{amsmath}')
# Settings:
fs_chart = 70
fs_lines = 75
fs_legend = 40
titles_fontsize = 50
titles_figsize = (4, 2.5)
elements_fontsize = 80
elements_figsize = (3, 3)
lines_fontsize = 80
lines_figsize = (3, 3)
show_figs = True
grid_props = dict(left=0, right=1, top=1, bottom=0)
@@ -35,51 +38,56 @@ text_props = {
# Targets:
texts = {
# CIRCUIT ELEMENTS:
# 'filt': (r'$x_{\text{filt}}$', fs_chart, (3, 3)),
# 'env': (r'$x_{\text{env}}$', fs_chart, (3, 3)),
# 'db': (r'$x_{\text{dB}}$', fs_chart, (3, 3)),
# 'envdb': (r'$\begin{array}{c}x_{\text{env}}\\x_{\text{dB}}\end{array}$', fs_chart, (3, 3)),
# 'adapt': (r'$x_{\text{adapt}}$', fs_chart, (3, 3)),
# 'conv1': (r'$c_1$', fs_chart, (3, 3)),
# 'conv2': (r'$c_2$', fs_chart, (3, 3)),
# 'conv3': (r'$c_3$', fs_chart, (3, 3)),
# 'bi1': (r'$b_{1, \Theta}$', fs_chart, (3, 3)),
# 'bi2': (r'$b_{2, \Theta}$', fs_chart, (3, 3)),
# 'bi3': (r'$b_{3, \Theta}$', fs_chart, (3, 3)),
# 'feat1': (r'$f_{1, \Theta}$', fs_chart, (3, 3)),
# 'feat2': (r'$f_{2, \Theta}$', fs_chart, (3, 3)),
# 'feat3': (r'$f_{3, \Theta}$', fs_chart, (3, 3)),
# 'out': (r'$\hat{y}$', fs_chart, (3, 3)),
# # TITLES (NEURONAL CIRCUIT):
# 'neuron_titles_tympanum': ('Tympanal\nMembrane', titles_fontsize, titles_figsize),
# 'neuron_titles_receptors': ('Receptor\nNeurons', titles_fontsize, titles_figsize),
# 'neuron_titles_interneurons': ('Local\nInterneurons', titles_fontsize, titles_figsize),
# 'neuron_titles_ascending': ('Ascending\nNeurons', titles_fontsize, titles_figsize),
# 'neuron_titles_brain': ('Central\nBrain', titles_fontsize, titles_figsize),
# CIRCUIT OPERATIONS:
'rectlp': (r'$\lvert\cdot\lvert,h_{\text{LP}}$', fs_lines, (3, 3)),
'log': (r'$\text{log}$', fs_lines, (3, 3)),
'rectlplog': (r'$\begin{array}{c}||,h_{\text{LP}}\\\text{log}\end{array}$', fs_lines, (3, 3)),
'k1': (r'$k_1$', fs_lines, (3, 3)),
'k2': (r'$k_2$', fs_lines, (3, 3)),
'k3': (r'$k_3$', fs_lines, (3, 3)),
'bp': (r'$h_{\text{BP}}$', fs_lines, (3, 3)),
'lp': (r'$h_{\text{LP}}$', fs_lines, (3, 3)),
'hp': (r'$h_{\text{HP}}$', fs_lines, (3, 3)),
'theta1': (r'$\Theta_1$', fs_lines, (3, 3)),
'theta2': (r'$\Theta_2$', fs_lines, (3, 3)),
'theta3': (r'$\Theta_3$', fs_lines, (3, 3)),
'w1': (r'$\omega_1$', fs_lines, (3, 3)),
'w2': (r'$\omega_2$', fs_lines, (3, 3)),
'w3': (r'$\omega_3$', fs_lines, (3, 3)),
'thresh1': (r'$H(c_1-\Theta_1)$', fs_lines, (3, 3)),
'thresh2': (r'$H(c_2-\Theta_2)$', fs_lines, (3, 3)),
'thresh3': (r'$H(c_3-\Theta_3)$', fs_lines, (3, 3)),
# # TITLES (MODEL CIRCUIT):
# 'model_titles_bandpass': ('Bandpass\nFiltering', titles_fontsize, titles_figsize),
# 'model_titles_envelope': ('Envelope\nExtraction', titles_fontsize, titles_figsize),
# 'model_titles_logarithm': ('Logarithmic\nCompression', titles_fontsize, titles_figsize),
# 'model_titles_adaptation': ('Intensity\nAdaptation', titles_fontsize, titles_figsize),
# 'model_titles_convolution': ('Convolutional\nFiltering', titles_fontsize, titles_figsize),
# 'model_titles_nonlinear': ('Threshold\nNonlinearity', titles_fontsize, titles_figsize),
# 'model_titles_integration': ('Temporal\nAveraging', titles_fontsize, titles_figsize),
# 'model_titles_readout': ('Weighted\nReadout', titles_fontsize, titles_figsize),
# LEGEND ELEMENTS:
# 'tympanum': ('Tympanal\nMembrane', fs_legend, (3, 3)),
# 'receptors': ('Receptor\nNeuron\nPopulation', fs_legend, (3, 3)),
# 'interneurons': ('Local\nInterneuron\nPopulation', fs_legend, (3, 3)),
# 'ascending': ('Individual\nAscending\nNeurons', fs_legend, (3, 3)),
# 'threshold': ('Threshold\nNonlinearity', fs_legend, (3, 3)),
# 'integration': ('Temporal\nAveraging', fs_legend, (3, 3)),
# 'brain': ('Weighting\nand\nReadout', fs_legend, (3, 3)),
# # ELEMENT LABELS (MODEL CIRCUIT):
# 'model_elements_filt': (r'$x_{\text{filt}}$', elements_fontsize, elements_figsize),
# 'model_elements_env': (r'$x_{\text{env}}$', elements_fontsize, elements_figsize),
# 'model_elements_log': (r'$x_{\text{dB}}$', elements_fontsize, elements_figsize),
# 'model_elements_adapt': (r'$x_{\text{adapt}}$', elements_fontsize, elements_figsize),
# 'model_elements_c1': (r'$c_1$', elements_fontsize, elements_figsize),
# 'model_elements_c2': (r'$c_2$', elements_fontsize, elements_figsize),
# 'model_elements_c3': (r'$c_3$', elements_fontsize, elements_figsize),
# 'model_elements_b1': (r'$b_1$', elements_fontsize, elements_figsize),
# 'model_elements_b2': (r'$b_2$', elements_fontsize, elements_figsize),
# 'model_elements_b3': (r'$b_3$', elements_fontsize, elements_figsize),
# 'model_elements_f1': (r'$f_1$', elements_fontsize, elements_figsize),
# 'model_elements_f2': (r'$f_2$', elements_fontsize, elements_figsize),
# 'model_elements_f3': (r'$f_3$', elements_fontsize, elements_figsize),
# 'model_elements_out': (r'$\hat{y}$', elements_fontsize, elements_figsize),
# LINE LABELS (MODEL CIRCUIT):
'model_lines_env': (r'$\lvert\cdot\lvert,h_{\text{LP}}$', lines_fontsize, lines_figsize),
'model_lines_log': (r'$\text{log}$', lines_fontsize, lines_figsize),
'model_lines_hp': (r'$h_{\text{HP}}$', lines_fontsize, lines_figsize),
'model_lines_k1': (r'$k_1$', lines_fontsize, lines_figsize),
'model_lines_k2': (r'$k_2$', lines_fontsize, lines_figsize),
'model_lines_k3': (r'$k_3$', lines_fontsize, lines_figsize),
'model_lines_t1': (r'$\Theta_1$', lines_fontsize, lines_figsize),
'model_lines_t2': (r'$\Theta_2$', lines_fontsize, lines_figsize),
'model_lines_t3': (r'$\Theta_3$', lines_fontsize, lines_figsize),
# 'model_lines_H1': (r'$H(c_1-\Theta_1)$', lines_fontsize, lines_figsize),
# 'model_lines_H2': (r'$H(c_2-\Theta_2)$', lines_fontsize, lines_figsize),
# 'model_lines_H3': (r'$H(c_3-\Theta_3)$', lines_fontsize, lines_figsize),
'model_lines_lp': (r'$h_{\text{LP}}$', lines_fontsize, lines_figsize),
'model_lines_w1': (r'$\omega_1$', lines_fontsize, lines_figsize),
'model_lines_w2': (r'$\omega_2$', lines_fontsize, lines_figsize),
'model_lines_w3': (r'$\omega_3$', lines_fontsize, lines_figsize),
}
# Save each target string:
@@ -93,135 +101,3 @@ for name, (text, fs, size) in texts.items():
if show_figs:
plt.show()
plt.close(fig)
# def text_box(ax, text, xy, width, height, transform=None,
# ha='center', va='center', **kwargs):
# """ Maximizes fontsize of text to fit into a given bounding box.
# Calculated fontsize depends on the aspect ratio of the bounding box,
# the aspect ratio and alignment of the text, and the resolution and size
# of the underlying figure. Text is not updated when resizing the figure.
# Parameters
# ----------
# ax : matplotlib axes object
# Target subplot to annotate the text.
# text : str
# Text to fit into the specified bounding box under the given alignments.
# xy : tuple of floats or ints (2,)
# Text position in the coordinate system specified by transform.
# width : float or int
# Rectangle width in the coordinate system specified by transform.
# height : float or int
# Rectangle height in the coordinate system specified by transform.
# transform : matplotlib transform, optional
# Underlying coordinate system of the bounding box. Determines the
# interpretation of xy, width, and height. Falls back to data coordinates
# if unspecified. The default is None.
# ha : str, optional
# Horizontal alignment of bounding box and text relative to the given xy.
# The default is 'center'.
# va : str, optional
# Vertical alignment of bounding box and text relative to the given xy.
# The default is 'center'.
# **kwargs : dict, optional
# Additional keyword arguments passed to ax.annotate() for specifying
# different font properties of the returned text object.
# Returns
# -------
# t : matplotlib text object
# Annotated text object with adjusted fontsize to fit the bounding box.
# """
# # Input interpretation:
# if transform is None:
# transform = ax.transData
# fig = ax.get_figure()
# x, y = xy
# # Alignment-specific anchor points:
# x_align1, x_align2 = {
# 'center': (x - width / 2, x + width / 2),
# 'left': (x, x + width),
# 'right': (x - width, x),
# }[ha]
# y_align1, y_align2 = {
# 'center': (y - height / 2, y + height / 2),
# 'bottom': (y, y + height),
# 'top': (y - height, y),
# }[va]
# # Anchor points in pixel:
# left_corner = transform.transform((x_align1, y_align1))
# right_corner = transform.transform((x_align2, y_align2))
# # Bounding rectangle size in pixel:
# pixel_width = right_corner[0] - left_corner[0]
# pixel_height = right_corner[1] - left_corner[1]
# # Adjust fontsize to box height (inch):
# dpi = fig.dpi
# rect_height = pixel_height / dpi
# fs_initial = rect_height * 72
# # Plot first draft of the text:
# t = ax.annotate(text, xy, ha=ha, va=va, xycoords=transform, **kwargs)
# t.set_fontsize(fs_initial)
# # Adjust fontsize to box width (inch):
# bbox = t.get_window_extent(fig.canvas.get_renderer())
# fs_adjusted = fs_initial * pixel_width / bbox.width
# t.set_fontsize(fs_adjusted)
# return t
# def text_graph(text, save_str=None, size=None, ax=None, show=False,
# close=False, **kwargs):
# """ Turns entire subplot into a text box that displays the given text.
# Fontsize is maximized to fit the available bounding box. Text is always
# centered in the subplot. Meant for creating scalable text elements that
# comply with the style of other plot elements, especially for posters.
# Parameters
# ----------
# text : str
# Text to be displayed. Can be multiline. Text fontsize is maximized by
# text_box() to fit a bounding box that covers the entire axes area.
# save_str : str, optional
# If specified, saves the underlying figure under the given path. For
# best results, use a vector format such as .svg). The default is None.
# size : tuple of floats or ints (2,), optional
# If specified, creates a new figure with given size in inches and a
# single subplot. Indirectly controls the aspect ratio of the text box.
# Must be specified if ax is None. The default is None.
# ax : matplotlib axes object, optional
# If specified, the target subplot to turn into a text box. Can be used
# to set more properties such as the background color of the text box.
# Must be specified if size is None. The default is None.
# show : bool, optional
# If True, displays the figure before returning. Else, returns without
# showing the figure. The default is False.
# **kwargs : dict, optional
# Keyword arguments passed to text_box() and further to ax.annotate() for
# specifying additional font properties of the displayed text.
# Raises
# ------
# ValueError
# Breaks if neither size nor ax is specified to define a target subplot.
# """
# # Input interpretation:
# if size is not None:
# fig, ax = plt.subplots(figsize=size)
# elif ax is not None:
# fig = ax.get_figure()
# else:
# raise ValueError('Either size or ax must be specified.')
# # Turn drawable area of axes into a single text box:
# text_box(ax, text, (0.5, 0.5), 1, 1, ax.transAxes, **kwargs)
# # Hide other axes elements:
# ax.xaxis.set_visible(False)
# ax.yaxis.set_visible(False)
# ax.spines[:].set_visible(False)
# # Return options:
# if save_str is not None:
# fig.savefig(save_str, bbox_inches='tight')
# if show:
# plt.show()
# return None

View File

@@ -0,0 +1,24 @@
import numpy as np
# NEURON CIRCUIT (WIDTH):
# total_space = 32
# side_space = 0.5
# n_posts = 5
# MODEL CIRCUIT (WIDTH):
total_space = 48
side_space = 0.5
n_posts = 8
# RUN SOLVER:
post_space = np.arange(1, (total_space - 2 * side_space) // n_posts + 1)
available_space = total_space - 2 * side_space - n_posts * post_space
inter_space = available_space / (n_posts - 1)
remaining_space = available_space % (n_posts - 1)
# REPORT OUTCOMES:
print('\nPost Width - Inter-Post - Remainder:')
for input, output, remainder in zip(post_space, inter_space, remaining_space):
print(input, output, remainder)
print()