Skip to content

Commit

Permalink
new plotting kwarg mechanism
Browse files Browse the repository at this point in the history
+bug fixes in spike_plotter
  • Loading branch information
zm711 committed Nov 30, 2023
1 parent c2eb94e commit 395c9fd
Show file tree
Hide file tree
Showing 3 changed files with 275 additions and 69 deletions.
36 changes: 36 additions & 0 deletions src/spikeanalysis/plotbase.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations
from collections import namedtuple
from typing import Optional
import matplotlib.pyplot as plt

Expand Down Expand Up @@ -43,3 +44,38 @@ def _set_kwargs(self, **kwargs):
self.title = kwargs["title"]
if "figsize" in kwargs:
self.figsize = kwargs["figsize"]

def convert_plot_kwargs(self, plot_kwargs: dict) -> namedtuple:
"""If given a dict of kwargs converts to namedtuple otherwise
uses the global kwargs set for plotting
Parameters
----------
plot_kwargs: dict
the matplotlib style kwargs to use
"""

figsize = plot_kwargs.pop("figsize", self.figsize)
dpi = plot_kwargs.pop("dpi", self.dpi)
x_lim = plot_kwargs.pop("xlim", None)
y_lim = plot_kwargs.pop("ylim", None)

title = plot_kwargs.pop("title", self.title)
cmap = plot_kwargs.pop("cmap", self.cmap)

x_axis = plot_kwargs.pop("x_axis", self.x_axis)
y_axis = plot_kwargs.pop("y_axis", self.y_axis)

PlotKwargs = namedtuple("PlotKwargs", ["figsize", "dpi", "x_lim", "y_lim", "title", "cmap", "x_axis", "y_axis"])

plot_kwargs = PlotKwargs(figsize, dpi, x_lim, y_lim, title, cmap, x_axis, y_axis)

return plot_kwargs

def set_plot_kwargs(self, ax: plt.axes, plot_kwargs: namedtuple):
if plot_kwargs.x_lim is not None:
ax.set_xlim(plot_kwargs.x_lim)

if plot_kwargs.y_lim is not None:
ax.set_ylim(plot_kwargs.y_lim)
Loading

0 comments on commit 395c9fd

Please sign in to comment.