Skip to content

Commit

Permalink
Merge pull request #271 from NeuroML/feat/matplotlib-allow-rc-overrides
Browse files Browse the repository at this point in the history
feat(plotter): use matplotlib rcparams defaults for missing options
  • Loading branch information
sanjayankur31 authored Nov 7, 2023
2 parents a3caa2f + f868ab6 commit e2d9123
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
21 changes: 12 additions & 9 deletions pyneuroml/plot/Plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def generate_plot(
grid: bool = False,
logx: bool = False,
logy: bool = False,
font_size: int = 12,
font_size: typing.Optional[int] = None,
bottom_left_spines_only: bool = False,
cols_in_legend_box: int = 3,
legend_position: typing.Optional[str] = "best",
Expand Down Expand Up @@ -103,7 +103,7 @@ def generate_plot(
:type logx: boolean
:param logy: should the y ayis be in log scale (default: False)
:type logy: boolean
:param font_size: font size (default: 12)
:param font_size: font size
:type font_size: float
:param bottom_left_spines_only: enable/disable spines on right and top (default: False)
(a spine is the line noting the data area boundary)
Expand Down Expand Up @@ -137,7 +137,8 @@ def generate_plot(
from matplotlib import pyplot as plt
from matplotlib import rcParams

rcParams.update({"font.size": font_size})
if font_size is not None:
rcParams.update({"font.size": font_size})

fig = plt.figure()
ax = fig.add_subplot(111)
Expand All @@ -152,7 +153,7 @@ def generate_plot(
plt.ylabel(yaxis)

if grid:
plt.grid("on")
plt.grid(True)

if logx:
ax.set_xscale("log")
Expand All @@ -171,12 +172,13 @@ def generate_plot(
ax.set_yticklabels([])

for i in range(len(xvalues)):

linestyle = "-" if not linestyles else linestyles[i]
linestyle = rcParams["lines.linestyle"] if not linestyles else linestyles[i]
label = "" if not labels else labels[i]
marker = None if not markers else markers[i]
linewidth = 1 if not linewidths else linewidths[i]
markersize = None if not markersizes else markersizes[i]
marker = rcParams["lines.marker"] if not markers else markers[i]
linewidth = rcParams["lines.linewidth"] if not linewidths else linewidths[i]
markersize = (
rcParams["lines.markersizes"] if not markersizes else markersizes[i]
)

if colors:
plt.plot(
Expand Down Expand Up @@ -374,6 +376,7 @@ def generate_interactive_plot(
:type save_figure_to: str
"""
import plotly.graph_objects as go

fig = go.Figure()

if len(xvalues) != len(yvalues):
Expand Down
15 changes: 14 additions & 1 deletion pyneuroml/plot/PlotSpikes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#!/usr/bin/env python3
"""
Spike plotting helper functions.
File: pyneuroml/plot/PlotSpikes.py
Copyright 2023 NeuroML contributors
"""
import argparse
import logging
import os
Expand Down Expand Up @@ -104,7 +112,12 @@ def main(args=None):
run(a=args)


def read_sonata_spikes_hdf5_file(file_name):
def read_sonata_spikes_hdf5_file(file_name: str):
"""Read a sonata HDF5 file with spike data
:param file_name: name of file to read
:type file_name: str
"""
full_path = os.path.abspath(file_name)
logger.info("Loading SONATA spike times from: %s (%s)" % (file_name, full_path))

Expand Down

0 comments on commit e2d9123

Please sign in to comment.