Switch to Black-enforced code style.

master
Damien Goutte-Gattat 2 months ago
parent 49356aded0
commit 5b62023202
  1. 38
      incenp/plotting/bar.py
  2. 59
      incenp/plotting/scatter.py
  3. 6
      incenp/plotting/util.py
  4. 2
      pyproject.toml
  5. 11
      setup.py

@ -26,7 +26,7 @@ from numpy import arange as _arange
def get_subtrack_offset(n_subtrack, max_subtrack, width):
"""Get the X offset to center a subtrack around an origin.
:param n_subtrack: The 0-based subtrack index
:param max_subtrack: The number of subtracks
:param The width of a single subtrack
@ -40,10 +40,20 @@ def get_subtrack_offset(n_subtrack, max_subtrack, width):
return base_offset + subtrack_offset + center_offset
def barplot(ax, data, column, tracks, subtracks=[None], subtrackname=1,
ncolumn=None, nformat="n={}", colors='rgb', width=.25):
def barplot(
ax,
data,
column,
tracks,
subtracks=[None],
subtrackname=1,
ncolumn=None,
nformat="n={}",
colors='rgb',
width=0.25,
):
"""Create a barplot from multi-indexed data.
:param ax: The matplotlib axis to draw on
:param data: The data from which the values to plot are taken
:param column: The name of the column in the data frame containing
@ -63,9 +73,9 @@ def barplot(ax, data, column, tracks, subtracks=[None], subtrackname=1,
for s, subtrack in enumerate(subtracks):
if subtrack is not None:
level = subtrackname if data.index.nlevels > 1 else None
subset = data.xs(subtrack, level=level).loc[tracks,:]
subset = data.xs(subtrack, level=level).loc[tracks, :]
else:
subset = data.loc[tracks,:]
subset = data.loc[tracks, :]
x = _arange(len(subset))
ax.set_xticks(x)
@ -76,12 +86,14 @@ def barplot(ax, data, column, tracks, subtracks=[None], subtrackname=1,
for i, rect in enumerate(rects):
height = rect.get_height()
n = subset.loc[tracks, ncolumn][i]
ax.annotate(nformat.format(n),
xy=(rect.get_x() + rect.get_width() / 2, height),
xytext=(0, 5),
textcoords='offset points',
ha='center', va='center',
fontsize='xx-small')
ax.annotate(
nformat.format(n),
xy=(rect.get_x() + rect.get_width() / 2, height),
xytext=(0, 5),
textcoords='offset points',
ha='center',
va='center',
fontsize='xx-small',
)
ax.set_xticklabels(tracks)

@ -24,10 +24,11 @@ plots from multi-indexed Panda datasets.
from .util import xdistr, get_stars
def scatterplot_subtrack(ax, data, n_track, n_subtrack, max_subtrack,
color, width=.7, min_sep=-.05):
def scatterplot_subtrack(
ax, data, n_track, n_subtrack, max_subtrack, color, width=0.7, min_sep=-0.05
):
"""Plot a single subtrack.
:param ax: The matplotlib axis to draw on
:param data: The data series from which the values to plot are taken
:param n_track: Offset of the current track
@ -41,18 +42,27 @@ def scatterplot_subtrack(ax, data, n_track, n_subtrack, max_subtrack,
"""
offset = n_track * max_subtrack + n_subtrack
xs = xdistr(data.values, width, center=True, min_sep=min_sep,
offset=offset)
xs = xdistr(data.values, width, center=True, min_sep=min_sep, offset=offset)
ax.plot(xs, data.values, color=color, marker='.', linestyle='')
ax.hlines(data.mean(), offset - .5, offset + .5, color)
def scatterplot(ax, data, columns, subtrackcolumns=False,
tracks=[None], trackname=0,
subtracks=[None], subtrackname=1,
colors='rgb', width=.7, min_sep=-.05, testfunc=None):
ax.hlines(data.mean(), offset - 0.5, offset + 0.5, color)
def scatterplot(
ax,
data,
columns,
subtrackcolumns=False,
tracks=[None],
trackname=0,
subtracks=[None],
subtrackname=1,
colors='rgb',
width=0.7,
min_sep=-0.05,
testfunc=None,
):
"""Create a scatterplot from multi-indexed data.
:param ax: The matplotlib axis to draw on
:param data: The data frame from which the values to plot are taken
:param columns: The name of the column(s) in the data frame
@ -105,8 +115,7 @@ def scatterplot(ax, data, columns, subtrackcolumns=False,
for subtrack in subtracks:
subset = _get_dataseries(data, column, subtrack, subtrackname)
testset.append(subset)
scatterplot_subtrack(ax, subset, i, j, n, colors[j % n], width,
min_sep)
scatterplot_subtrack(ax, subset, i, j, n, colors[j % n], width, min_sep)
j += 1
if testfunc and len(subtracks) == 2:
@ -124,8 +133,9 @@ def scatterplot(ax, data, columns, subtrackcolumns=False,
for column in columns:
subset = _get_dataseries(data, column, track, trackname)
testset.append(subset)
scatterplot_subtrack(ax, subset, i, j, n, colors[j % n],
width, min_sep)
scatterplot_subtrack(
ax, subset, i, j, n, colors[j % n], width, min_sep
)
j += 1
else:
for subtrack in subtracks:
@ -135,11 +145,11 @@ def scatterplot(ax, data, columns, subtrackcolumns=False,
else:
level = [trackname]
subset = _get_dataseries(data, columns, indexer,
level=level)
subset = _get_dataseries(data, columns, indexer, level=level)
testset.append(subset)
scatterplot_subtrack(ax, subset, i, j, n, colors[j % n],
width, min_sep)
scatterplot_subtrack(
ax, subset, i, j, n, colors[j % n], width, min_sep
)
j += 1
if testfunc and len(testset) == 2:
@ -147,7 +157,7 @@ def scatterplot(ax, data, columns, subtrackcolumns=False,
i += 1
ax.set_xticks([(.5 * (n - 2)) + n * i for i in range(len(labels))])
ax.set_xticks([(0.5 * (n - 2)) + n * i for i in range(len(labels))])
ax.set_xticklabels(labels)
@ -164,6 +174,5 @@ def _do_test(ax, testset, testfunc, n_track, max_subtrack):
if pvalue:
y = max(testset[0].max(), testset[1].max()) * 1.1
offset = n_track * max_subtrack
ax.hlines(y, offset - .5, offset + 1.5)
ax.text(offset + .5, y, get_stars(pvalue), ha='center', va='bottom')
ax.hlines(y, offset - 0.5, offset + 1.5)
ax.text(offset + 0.5, y, get_stars(pvalue), ha='center', va='bottom')

@ -18,12 +18,12 @@
"""Miscellaneous utility functions for plotting tasks."""
def xdistr(values, width, offset=0, even_max=10, center=False, min_sep=-.05):
def xdistr(values, width, offset=0, even_max=10, center=False, min_sep=-0.05):
"""Distribute coordinates around an axis.
Given a list of values, return an array of x coordinates so that
the plotted values are equally distributed.
:param values: The list of values to distribute
:param width: The distance along which to distribute the values
:param offset: An offset to apply to each returned coordinates

@ -0,0 +1,2 @@
[tool.black]
skip-string-normalization = true

@ -36,16 +36,15 @@ setup(
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'Programming Language :: Python :: 3.7',
'Topic :: Scientific/Engineering :: Visualization',
'Topic :: Software Development :: Libraries :: Python Modules'
],
'Topic :: Software Development :: Libraries :: Python Modules',
],
packages=find_packages(),
include_package_data=True,
command_options={
'build_sphinx': {
'project': ('setup.py', 'Pyplot'),
'version': ('setup.py', __version__),
'release': ('setup.py', __version__)
}
'release': ('setup.py', __version__),
}
)
},
)

Loading…
Cancel
Save