From 8f8b53613193754075f21a398284ed48b00f37f5 Mon Sep 17 00:00:00 2001 From: Utkarsha Dunde Date: Sat, 14 Mar 2026 18:02:27 +0530 Subject: [PATCH 1/4] Fix: correctly pipe keyword arguments to plot_dendrogram --- brian2tools/plotting/base.py | 5 +---- brian2tools/plotting/morphology.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/brian2tools/plotting/base.py b/brian2tools/plotting/base.py index 28bb385d..83749c15 100644 --- a/brian2tools/plotting/base.py +++ b/brian2tools/plotting/base.py @@ -106,10 +106,7 @@ def brian_plot(brian_obj, kwds['rate_unit'] = _get_best_unit(smooth_rate) return plot_rate(brian_obj.t, smooth_rate, axes=axes, **kwds) elif isinstance(brian_obj, Morphology): - if kwds: - logger.warn('plot_dendrogram does not take any additional keyword ' - 'arguments, ignoring them.') - return plot_dendrogram(brian_obj, axes=axes) + return plot_dendrogram(brian_obj, axes=axes, **kwds) elif isinstance(brian_obj, Synapses): if len(brian_obj) == 0: raise TypeError('Synapses object does not have any synapses.') diff --git a/brian2tools/plotting/morphology.py b/brian2tools/plotting/morphology.py index 08cdbfdf..49b380fa 100644 --- a/brian2tools/plotting/morphology.py +++ b/brian2tools/plotting/morphology.py @@ -353,7 +353,7 @@ def plot_morphology(morphology, plot_3d=None, show_compartments=False, return axes -def plot_dendrogram(morphology, axes=None): +def plot_dendrogram(morphology, axes=None, **kwds): ''' Plot a "dendrogram" of a morphology, i.e. an abstract representation which visualizes the branching structure and the length of each section. @@ -366,6 +366,10 @@ def plot_dendrogram(morphology, axes=None): The `~matplotlib.axes.Axes` instance used for plotting. Defaults to ``None`` which means that a new `~matplotlib.axes.Axes` will be created for the plot. + kwds : dict, optional + Any additional keywords command will be handed over to matplotlib's + `~matplotlib.axes.Axes.plot` command. This can be used to set plot + properties such as the ``color``. Returns ------- @@ -427,7 +431,7 @@ def plot_dendrogram(morphology, axes=None): # Plot the dendogram with lengths of the vertical lines representing the # total distance to the root - plt.plot(x_values[0], length_metric[0], 'ko', clip_on=False) + plt.plot(x_values[0], length_metric[0], marker='o', clip_on=False, **kwds) for sec, (x, depth) in enumerate(zip(x_values, length_metric)): child_start_idx = (sec+1)*max_children num_children = flat_morpho.morph_children_num[sec+1] @@ -435,8 +439,8 @@ def plot_dendrogram(morphology, axes=None): child_indices = children[child_start_idx:child_start_idx+num_children] child_depth = length_metric[child_indices-1] child_x = x_values[child_indices-1] - axes.vlines(child_x, depth, child_depth, clip_on=False, lw=2) - axes.hlines(depth, min(child_x), max(child_x), lw=2) + axes.vlines(child_x, depth, child_depth, clip_on=False, lw=2, **kwds) + axes.hlines(depth, min(child_x), max(child_x), lw=2, **kwds) axes.set_xticks([]) axes.set_ylabel('distance from root (um)') axes.set_xlim(-1, terminal_counter) From 56982fcf7681b71aceb15dfa15d6c7ad1d34695f Mon Sep 17 00:00:00 2001 From: Utkarsha Dunde Date: Sat, 21 Mar 2026 22:59:06 +0530 Subject: [PATCH 2/4] Addressing review comments. --- brian2tools/plotting/morphology.py | 10 ++++++---- brian2tools/tests/test_plotting.py | 14 ++++++++++++++ docs_sphinx/user/plotting.rst | 8 +++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/brian2tools/plotting/morphology.py b/brian2tools/plotting/morphology.py index 69b2b5db..43c3477b 100644 --- a/brian2tools/plotting/morphology.py +++ b/brian2tools/plotting/morphology.py @@ -365,10 +365,12 @@ def plot_dendrogram(morphology, axes=None, **kwds): The `~matplotlib.axes.Axes` instance used for plotting. Defaults to ``None`` which means that a new `~matplotlib.axes.Axes` will be created for the plot. - kwds : dict, optional - Any additional keywords command will be handed over to matplotlib's - `~matplotlib.axes.Axes.plot` command. This can be used to set plot - properties such as the ``color``. + **kwds + Any additional keyword arguments are passed to matplotlib's + `~matplotlib.axes.Axes.plot`, `~matplotlib.axes.Axes.vlines`, and + `~matplotlib.axes.Axes.hlines` calls. Only arguments accepted by all + three functions should be used (e.g. ``color``, ``alpha``, + ``linewidth``). Returns ------- diff --git a/brian2tools/tests/test_plotting.py b/brian2tools/tests/test_plotting.py index 1b6fd085..e1ec6a29 100644 --- a/brian2tools/tests/test_plotting.py +++ b/brian2tools/tests/test_plotting.py @@ -122,6 +122,20 @@ def test_plot_morphology(): ax = plot_dendrogram(morpho) assert isinstance(ax, matplotlib.axes.Axes) plt.close() + # Test that styling kwargs are accepted and forwarded without error + ax = plot_dendrogram(morpho, color='red') + assert isinstance(ax, matplotlib.axes.Axes) + plt.close() + ax = plot_dendrogram(morpho, color='blue', alpha=0.5) + assert isinstance(ax, matplotlib.axes.Axes) + plt.close() + ax = plot_dendrogram(morpho, color='green', linewidth=3) + assert isinstance(ax, matplotlib.axes.Axes) + plt.close() + # brian_plot routes Morphology to plot_dendrogram, so kwargs must work there too + ax = brian_plot(morpho, color='purple') + assert isinstance(ax, matplotlib.axes.Axes) + plt.close() ax = plot_morphology(morpho) assert isinstance(ax, matplotlib.axes.Axes) plt.close() diff --git a/docs_sphinx/user/plotting.rst b/docs_sphinx/user/plotting.rst index 0b8420f4..815c489c 100644 --- a/docs_sphinx/user/plotting.rst +++ b/docs_sphinx/user/plotting.rst @@ -228,9 +228,11 @@ dendogram:: .. image:: ../images/plot_dendrogram.svg -The `~brian2tools.plotting.morphology.plot_dendrogram` function does the same thing, but in contrast to the other -plot functions it does not allow any customization at the moment, so there is no benefit over using -`~brian2tools.plotting.base.brian_plot`. +The `~brian2tools.plotting.morphology.plot_dendrogram` function does the same thing, but also accepts additional +keyword arguments (e.g. ``color``, ``alpha``, ``linewidth``) that are forwarded to the underlying +`~matplotlib.axes.Axes.plot`, `~matplotlib.axes.Axes.vlines`, and `~matplotlib.axes.Axes.hlines` calls:: + + plot_dendrogram(morpho, color='red', alpha=0.7) .. _plotting_morphologies: From 46e4c268cd5f6095e320d183777f49f00b5d831b Mon Sep 17 00:00:00 2001 From: Utkarsha Dunde Date: Thu, 26 Mar 2026 17:24:11 +0530 Subject: [PATCH 3/4] Addressing review comments. --- brian2tools/plotting/morphology.py | 9 ++++++--- docs_sphinx/user/plotting.rst | 14 +++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/brian2tools/plotting/morphology.py b/brian2tools/plotting/morphology.py index 43c3477b..e3ef95b6 100644 --- a/brian2tools/plotting/morphology.py +++ b/brian2tools/plotting/morphology.py @@ -430,9 +430,12 @@ def plot_dendrogram(morphology, axes=None, **kwds): x_values = (np.array(min_index) + np.array(max_index)) / 2.0 + clip_on = kwds.pop('clip_on', False) + lw = kwds.pop('lw', kwds.pop('linewidth', 2)) + # Plot the dendogram with lengths of the vertical lines representing the # total distance to the root - plt.plot(x_values[0], length_metric[0], marker='o', clip_on=False, **kwds) + plt.plot(x_values[0], length_metric[0], marker='o', clip_on=clip_on, **kwds) for sec, (x, depth) in enumerate(zip(x_values, length_metric)): child_start_idx = (sec+1)*max_children num_children = flat_morpho.morph_children_num[sec+1] @@ -440,8 +443,8 @@ def plot_dendrogram(morphology, axes=None, **kwds): child_indices = children[child_start_idx:child_start_idx+num_children] child_depth = length_metric[child_indices-1] child_x = x_values[child_indices-1] - axes.vlines(child_x, depth, child_depth, clip_on=False, lw=2, **kwds) - axes.hlines(depth, min(child_x), max(child_x), lw=2, **kwds) + axes.vlines(child_x, depth, child_depth, clip_on=clip_on, lw=lw, **kwds) + axes.hlines(depth, min(child_x), max(child_x), lw=lw, **kwds) axes.set_xticks([]) axes.set_ylabel('distance from root (um)') axes.set_xlim(-1, terminal_counter) diff --git a/docs_sphinx/user/plotting.rst b/docs_sphinx/user/plotting.rst index 815c489c..2e87c2b2 100644 --- a/docs_sphinx/user/plotting.rst +++ b/docs_sphinx/user/plotting.rst @@ -228,12 +228,20 @@ dendogram:: .. image:: ../images/plot_dendrogram.svg -The `~brian2tools.plotting.morphology.plot_dendrogram` function does the same thing, but also accepts additional -keyword arguments (e.g. ``color``, ``alpha``, ``linewidth``) that are forwarded to the underlying -`~matplotlib.axes.Axes.plot`, `~matplotlib.axes.Axes.vlines`, and `~matplotlib.axes.Axes.hlines` calls:: +The `~brian2tools.plotting.morphology.plot_dendrogram` function does the same thing, but in contrast to the other +plot functions it does not allow any customization that is not also available via +`~brian2tools.plotting.base.brian_plot`. Both functions accept additional keyword arguments (e.g. ``color``, +``alpha``, ``linewidth``) that are forwarded to the underlying `~matplotlib.axes.Axes.plot`, +`~matplotlib.axes.Axes.vlines`, and `~matplotlib.axes.Axes.hlines` calls:: plot_dendrogram(morpho, color='red', alpha=0.7) +.. image:: ../images/plot_dendrogram_custom.svg + +The same customization is also possible via `~brian2tools.plotting.base.brian_plot`:: + + brian_plot(morpho, color='red', alpha=0.7) + .. _plotting_morphologies: Morphologies in 2D or 3D From 95d546d9efdd624057156b5965e2c9cb51534755 Mon Sep 17 00:00:00 2001 From: Utkarsha Dunde Date: Fri, 27 Mar 2026 12:57:12 +0530 Subject: [PATCH 4/4] Generate and Commit missing plot, --- .../plotting_examples/morphology_plots.py | 6 + docs_sphinx/images/plot_dendrogram_custom.svg | 1372 +++++++++++++++++ 2 files changed, 1378 insertions(+) create mode 100644 docs_sphinx/images/plot_dendrogram_custom.svg diff --git a/dev/doc_tools/plotting_examples/morphology_plots.py b/dev/doc_tools/plotting_examples/morphology_plots.py index 9b8f9232..f99015c8 100644 --- a/dev/doc_tools/plotting_examples/morphology_plots.py +++ b/dev/doc_tools/plotting_examples/morphology_plots.py @@ -13,6 +13,12 @@ brian_plot(morpho) savefig(os.path.join(fig_dir, 'plot_dendrogram.svg')) close() + +figure() +plot_dendrogram(morpho, color='red', alpha=0.7) +savefig(os.path.join(fig_dir, 'plot_dendrogram_custom.svg')) +close() + plot_morphology(morpho) # 3d plot mayavi.show() figure() diff --git a/docs_sphinx/images/plot_dendrogram_custom.svg b/docs_sphinx/images/plot_dendrogram_custom.svg new file mode 100644 index 00000000..3193a3fc --- /dev/null +++ b/docs_sphinx/images/plot_dendrogram_custom.svg @@ -0,0 +1,1372 @@ + + + + + + + + 2026-03-27T12:49:53.629811 + image/svg+xml + + + Matplotlib v3.10.8, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +