pyneuroml.plot package#

pyneuroml.plot.Plot module#

Plotting helper functions.

File: pyneuroml/plot/Plot.py

Copyright 2023 NeuroML contributors

pyneuroml.plot.Plot.generate_interactive_plot(xvalues: List[float], yvalues: List[float], title: str, labels: Optional[List[str]] = None, linestyles: Optional[List[str]] = None, linewidths: Optional[Union[List[int], List[float]]] = None, markers: Optional[Union[List[str], List[int]]] = None, markersizes: Optional[Union[List[int], List[float]]] = None, plot_bgcolor: Optional[str] = None, modes: Optional[List[str]] = None, xaxis: Optional[str] = None, yaxis: Optional[str] = None, legend_title: Optional[str] = None, xaxis_color: str = '#fff', yaxis_color: str = '#fff', xaxis_width: Union[float, int] = 1, yaxis_width: Union[float, int] = 1, xaxis_mirror: Union[str, bool] = False, yaxis_mirror: Union[str, bool] = False, xaxis_spikelines: bool = False, yaxis_spikelines: bool = False, grid: bool = True, logx: bool = False, logy: bool = False, layout: Optional[dict] = None, show_interactive: bool = True, save_figure_to: Optional[str] = None) None#

Utility function to generate interactive plots using Plotly.

This function can be used to generate graphs with multiple plot lines. For example, to plot two metrics you can use:

generate_interactive_plot(xvalues=[[ax1, ax2, ax3], [bx1, bx2, bx3]], yvalues=[[ay1, ay2, ay3], [by1, by2, by3]], labels=["metric 1", "metric 2"])

Please note that while plotting multiple plots, you should take care to ensure that the number of x values and y values for each metric correspond. These lists are passed directly to Plotly for plotting without additional sanity checks.

A number of options are provided for convenience to allow plotting of multiple traces in the same plot and modification of common layout options. A layout dict can also be passed instead, which will overwrite any individually set options. If you need more customisation, please look at the source code of this method to write your own.

See the plotly documentation for more information: https://plotly.com/python-api-reference/generated/plotly.graph_objects.scatter.html

Parameters
pyneuroml.plot.Plot.generate_plot(xvalues: List[List[float]], yvalues: List[List[float]], title: str, labels: Optional[List[str]] = None, colors: Optional[List[str]] = None, linestyles: Optional[List[str]] = None, linewidths: Optional[List[str]] = None, markers: Optional[List[str]] = None, markersizes: Optional[List[str]] = None, xaxis: Optional[str] = None, yaxis: Optional[str] = None, xlim: Optional[List[float]] = None, ylim: Optional[List[float]] = None, show_xticklabels: bool = True, show_yticklabels: bool = True, grid: bool = False, logx: bool = False, logy: bool = False, font_size: int = 12, bottom_left_spines_only: bool = False, cols_in_legend_box: int = 3, legend_position: Optional[str] = 'best', show_plot_already: bool = True, save_figure_to: Optional[str] = None, title_above_plot: bool = False, verbose: bool = False) Axes#

Utility function to generate plots using the Matplotlib library.

This function can be used to generate graphs with multiple plot lines. For example, to plot two metrics you can use:

generate_plot(xvalues=[[ax1, ax2, ax3], [bx1, bx2, bx3]], yvalues=[[ay1, ay2, ay3], [by1, by2, by3]], labels=["metric 1", "metric 2"])

Please note that while plotting multiple plots, you should take care to ensure that the number of x values and y values for each metric correspond. These lists are passed directly to Matplotlib for plotting without additional sanity checks.

Please see the Matplotlib documentation for the complete list of available styles and colours: - https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html - https://matplotlib.org/stable/gallery/index.html

Parameters
  • xvalues (list of lists) – X values

  • yvalues (lists of lists) – Y values

  • title (str) – title of plot

  • labels (list of strings) – labels for each plot (default: None)

  • colors (list of strings) – colours for each plot (default: None)

  • linestyles (list strings) – list of line styles (default: None)

  • linewidths (list of floats) – list of line widths (default: None)

  • markers (list strings) – list of markers (default: None)

  • markersizes (list of floats) – list of marker sizes (default: None)

  • xaxis (str) – label of X axis (default: None)

  • yaxis (str) – label of Y axis (default: None)

  • xlim (tuple of (float, float) or individual arguments: (left=float), (right=float) See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.xlim.html) – left and right extents of x axis (default: None)

  • ylim (tuple of (float, float) or individual arguments: (top=float), (bottom=float) See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.ylim.html) – top and bottom extents of y axis (default: None)

  • show_xticklabels (boolean) – whether labels should be shown on xtics (default: True)

  • show_yticklabels (boolean) – whether labels should be shown on ytics (default: True)

  • grid (boolean) – enable/disable grid (default: False)

  • logx (boolean) – should the x axis be in log scale (default: False)

  • logy (boolean) – should the y ayis be in log scale (default: False)

  • font_size (float) – font size (default: 12)

  • bottom_left_spines_only (boolean) – enable/disable spines on right and top (default: False) (a spine is the line noting the data area boundary)

  • cols_in_legend_box (float) – number of columns to use in legend box (default: 3)

  • legend_position (str) –

    position of legend: See: https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.legend.html Extra options:

    • ”outer right” places the legend on the right, but outside the axes box

    • ”bottom center” places the legend on the bottom, below the figure

  • show_plot_already (boolean) – if plot should be shown when created (default: True)

  • save_figure_to (str) – location to save generated figure to (default: None)

  • title_above_plot (boolean) – enable/disable title above the plot (default: False)

  • verbose (boolean) – enable/disable verbose logging (default: False)

Returns

matplotlib.axes.Axes object

pyneuroml.plot.PlotSpikes module#

pyneuroml.plot.PlotSpikes.read_sonata_spikes_hdf5_file(file_name)#
pyneuroml.plot.PlotSpikes.run(a=None, **kwargs)#

pyneuroml.plot.PlotMorphology module#

Utilities to plot NeuroML2 cell morphologies.

File: pyneuroml/plot/PlotMorphology.py

Copyright 2023 NeuroML contributors

pyneuroml.plot.PlotMorphology.plot_2D(nml_file: str, plane2d: str = 'xy', min_width: float = 0, verbose: bool = False, nogui: bool = False, save_to_file: Optional[str] = None, square: bool = False)#

Plot cell morphology in 2D.

This uses matplotlib to plot the morphology in 2D.

Parameters
  • nml_file (str) – path to NeuroML cell file

  • plane2d (str) – what plane to plot (xy/yx/yz/zy/zx/xz)

  • min_width (float) – minimum width for segments (useful for visualising very thin segments): default 0.8um

  • verbose (bool) – show extra information (default: False)

  • nogui (bool) – do not show matplotlib GUI (default: false)

  • save_to_file (str) – optional filename to save generated morphology to

  • square (bool) – scale axes so that image is approximately square

pyneuroml.plot.PlotMorphology.plot_interactive_3D(nml_file: str, min_width: float = 0.8, verbose: bool = False, nogui: bool = False, save_to_file: Optional[str] = None)#

Plot NeuroML2 cell morphology interactively using Plot.ly

Please note that the interactive plot uses Plotly, which uses WebGL. So, you need to use a WebGL enabled browser, and performance here may be hardware dependent.

https://plotly.com/python/webgl-vs-svg/ https://en.wikipedia.org/wiki/WebGL

Parameters
  • nml_file (str) – path to NeuroML cell file

  • min_width (float) – minimum width for segments (useful for visualising very thin segments): default 0.8um

  • verbose (bool) – show extra information (default: False)

  • nogui (bool) – do not show matplotlib GUI (default: false)

  • save_to_file (str) – optional filename to save generated morphology to