Skip to content

Commit

Permalink
abstract plotting functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zm711 committed Oct 4, 2023
1 parent 1a2b81a commit 3c53932
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ omit = [
"src/spikeanalysis/analysis_utils/*", # utils are all numba
"src/spikeanalysis/spike_plotter.py", # no testing for actual plotting yet
"src/spikeanalysis/intrinsic_plotter.py", # no testing for plotting yet
"src/spikeanalysis/plotting.functions.py", # no test for plotting yet
]
1 change: 1 addition & 0 deletions src/spikeanalysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .analog_analysis import AnalogAnalysis
from .curated_spike_analysis import CuratedSpikeAnalysis, read_responsive_neurons
from .stats_functions import kolmo_smir_stats
from .plotting_functions import plot_piechart

import importlib.metadata

Expand Down
46 changes: 46 additions & 0 deletions src/spikeanalysis/plotting_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from typing import Optional, Sequence
import matplotlib.pyplot as plt


def plot_piechart(self, wedges: Sequence, counts: Sequence, colors: Optional[Sequence] = None):
"""Plots a piechart"""

assert len(wedges) == len(counts), "each wedge needs a corresponding count"
assert not counts.index(0), "counts with 0 will display incorrectly"
assert counts[0] != 0, "counts with 0 will display incorrectly"
import numpy as np

if self.figsize[0] <= 10:
fontsize = 10
else:
fontsize = 14

f, ax = plt.subplots(figsize=self.figsize)

if colors is None:
colors = [
"#ff9999",
"#66b3ff",
"#99ff99",
"#FEC8D8",
"#ffcc99",
"#F6BF85",
"#B7ADED",
]

ax.pie(
counts,
labels=wedges,
autopct=lambda pct: "{:.1f}%\n(n={:d})".format(pct, int(np.round(pct / 100 * np.sum(counts)))),
shadow=False,
startangle=90,
colors=colors,
textprops={"fontsize": fontsize},
)
ax.axis("equal")
if self.title:
plt.title(self.title)
plt.tight_layout()
plt.figure(dpi=self.dpi)

plt.show()

0 comments on commit 3c53932

Please sign in to comment.