Skip to content

Analysis

plot_symmetry(json_file='cect/cache/symmetry_measures.json', synclass='Chemical', datasets_to_plot=None)

Plot symmetry for specified synclass across selected datasets. Produces 3 subplots for SensorySomaticH, MotorSomaticH, InterneuronsSomaticH.

Parameters:

Name Type Description Default
json_file str

Path to the cached JSON file.

'cect/cache/symmetry_measures.json'
synclass str

Synapse class to plot, e.g., "Chemical".

'Chemical'
datasets_to_plot list

List of datasets to include. Defaults to all.

None
Source code in cect/Analysis.py
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
def plot_symmetry(
    json_file="cect/cache/symmetry_measures.json",
    synclass: str = "Chemical",
    datasets_to_plot=None,
):
    """
    Plot symmetry for specified synclass across selected datasets.
    Produces 3 subplots for SensorySomaticH, MotorSomaticH, InterneuronsSomaticH.

    Parameters:
        json_file (str): Path to the cached JSON file.
        synclass (str): Synapse class to plot, e.g., "Chemical".
        datasets_to_plot (list, optional): List of datasets to include. Defaults to all.
    """
    # Load JSON data
    with open(json_file, "r") as f:
        data = json.load(f)

    views = ["SensorySomaticH", "MotorSomaticH", "InterneuronsSomaticH"]

    if datasets_to_plot is None:
        datasets_to_plot = list(data.keys())

    fig, axes = plt.subplots(1, 3, figsize=(18, 5))
    fig.suptitle(f"Symmetry Across SomaticH Views ({synclass})", fontsize=16)

    for i, view in enumerate(views):
        ax = axes[i]
        y_vals = []
        labels = []

        for dataset in datasets_to_plot:
            val = data.get(dataset, {}).get(view, {}).get(synclass)
            if val is not None:
                try:
                    val = float(val)
                except ValueError:
                    continue
                y_vals.append(val)
                labels.append(dataset)

        ax.plot(labels, y_vals, marker="o", linestyle="-", color="tab:blue")
        ax.set_xticks(range(len(labels)))
        ax.set_xticklabels(labels, rotation=45, ha="right")

        ax.set_title(view, fontsize=14)
        ax.set_xlabel("Dataset", fontsize=12)
        ax.set_ylabel("Symmetry (%)", fontsize=12)
        ax.set_ylim(0, 105)
        ax.grid(True, linestyle="--", alpha=0.5)

    plt.tight_layout(rect=[0, 0, 1, 0.95])
    plt.show()