Initial commit.
This is Incenp.org's PyPlot, a Python helper library for plotting tasks.
This commit is contained in:
commit
1d18aaa2ca
|
@ -0,0 +1,7 @@
|
|||
.project
|
||||
.pydevproject
|
||||
.settings
|
||||
build
|
||||
dist
|
||||
*.egg-info
|
||||
__pycache__
|
|
@ -0,0 +1 @@
|
|||
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
|
|
@ -0,0 +1 @@
|
|||
__version__ = '0.1.0'
|
|
@ -0,0 +1,82 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Incenp.Plotting - Incenp.org's plotting helper library
|
||||
# Copyright © 2020 Damien Goutte-Gattat
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""Module description."""
|
||||
|
||||
from .util import xdistr
|
||||
|
||||
|
||||
def scatterplot_subtrack(ax, data, n_track, n_subtrack, max_subtrack, color, width=.7, min_sep=.1):
|
||||
offset = n_track * max_subtrack + n_subtrack
|
||||
xs = xdistr(data.values, width, center=True, min_sep=min_sep, offset=offset)
|
||||
ax.plot(xs, data.values, color + '.')
|
||||
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=.1):
|
||||
|
||||
if isinstance(columns, list):
|
||||
if subtrackcolumns:
|
||||
n = len(columns) + 1
|
||||
labels = tracks
|
||||
else:
|
||||
n = len(subtracks) + 1
|
||||
labels = columns
|
||||
else:
|
||||
n = len(subtracks) + 1
|
||||
labels = tracks
|
||||
|
||||
i = 0
|
||||
|
||||
if isinstance(columns, list) and not subtrackcolumns:
|
||||
for column in columns:
|
||||
j = 0
|
||||
|
||||
for subtrack in subtracks:
|
||||
if subtrack is None:
|
||||
subset = data.loc[:, column].dropna()
|
||||
else:
|
||||
level = subtrackname if data.index.nlevels > 1 else None
|
||||
subset = data.xs(subtrack, level=level).loc[:, column].dropna()
|
||||
scatterplot_subtrack(ax, subset, i, j, n, colors[j % n], width, min_sep)
|
||||
j += 1
|
||||
i += 1
|
||||
|
||||
else:
|
||||
for track in tracks:
|
||||
j = 0
|
||||
|
||||
if isinstance(columns, list) and subtrackcolumns:
|
||||
for column in columns:
|
||||
subset = data.xs(track, level=trackname).loc[:, column].dropna()
|
||||
scatterplot_subtrack(ax, subset, i, j, n, colors[j % n], width, min_sep)
|
||||
j += 1
|
||||
i += 1
|
||||
else:
|
||||
for subtrack in subtracks:
|
||||
indexer = [track, subtrack] if subtrack else [track]
|
||||
level = [trackname, subtrackname] if subtrack else [trackname]
|
||||
|
||||
subset = data.xs(indexer, level=level).loc[:, columns].dropna()
|
||||
scatterplot_subtrack(ax, subset, i, j, n, colors[j % n], width, min_sep)
|
||||
j += 1
|
||||
i += 1
|
||||
|
||||
ax.set_xticks([(.5 * (n - 2)) + n * i for i in range(len(labels))])
|
||||
ax.set_xticklabels(labels)
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Incenp.Plotting - Incenp.org's plotting helper library
|
||||
# Copyright © 2020 Damien Goutte-Gattat
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""Miscellaneous utility functions for plotting tasks."""
|
||||
|
||||
|
||||
def xdistr(values, width, offset=0, even_max=10, center=False, min_sep=1):
|
||||
"""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
|
||||
:param even_max: If the number of values on a given rank exceeds
|
||||
this parameter, they will be put closer together
|
||||
:param center: Distribute coordinates on both sides of offset
|
||||
:param min_sep: If two values differ by less than this parameter,
|
||||
they will be considered to belong on the same rank
|
||||
:return: An array of x coordinates
|
||||
"""
|
||||
|
||||
dist = {}
|
||||
spent = {}
|
||||
xcoords = []
|
||||
|
||||
values = [int(i / min_sep) for i in values]
|
||||
|
||||
# Get the distribution of values
|
||||
for v in values:
|
||||
if v in dist:
|
||||
dist[v] += 1
|
||||
else:
|
||||
dist[v] = 1
|
||||
spent[v] = 0
|
||||
|
||||
# Now proceeds
|
||||
for v in values:
|
||||
|
||||
# Compute step to distribute the values on the specified width
|
||||
step = width / max(even_max, dist[v])
|
||||
|
||||
if not center:
|
||||
x = offset + step * spent[v]
|
||||
elif spent[v] % 2 == 0:
|
||||
# If we've already drawn an even number of points,
|
||||
# draw the next one on the right of offset
|
||||
x = offset + (step / 2) * spent[v]
|
||||
else:
|
||||
# Draw the next point on the left of offset
|
||||
x = offset - (step / 2) * (spent[v] + 1)
|
||||
|
||||
# If there is an even number of points in that rank,
|
||||
# shift all points by a half-step
|
||||
if dist[v] % 2 == 0:
|
||||
x += step / 2
|
||||
|
||||
spent[v] += 1
|
||||
xcoords.append(x)
|
||||
|
||||
return xcoords
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Incenp.Plotting - Incenp.org's plotting helper library
|
||||
# Copyright © 2020 Damien Goutte-Gattat
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""Module description."""
|
||||
|
||||
from setuptools import setup, find_packages
|
||||
from incenp.plotting import __version__
|
||||
|
||||
setup(
|
||||
name='incenp.plotting',
|
||||
version=__version__,
|
||||
description='Incenp.org´s plotting helper library',
|
||||
author='Damien Goutte-Gattat',
|
||||
author_email='dgouttegattat@incenp.org',
|
||||
|
||||
packages=find_packages(),
|
||||
include_package_data=True
|
||||
)
|
Loading…
Reference in New Issue