Skip to content

Commit

Permalink
Fix setup.py and move to codeberg (#24)
Browse files Browse the repository at this point in the history
Co-authored-by: tfardet <[email protected]>
Co-authored-by: Tanguy Fardet <[email protected]>
Reviewed-on: https://codeberg.org/tfardet/mpl_chord_diagram/pulls/24
Co-Authored-By: Tanguy Fardet <[email protected]>
Co-Committed-By: Tanguy Fardet <[email protected]>
  • Loading branch information
Tanguy Fardet and tfardet committed Apr 7, 2021
1 parent 084df19 commit f25f27e
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 33 deletions.
37 changes: 25 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# mpl_chord_diagram

[![License](http://img.shields.io/github/license/Silmathoron/mpl_chord_diagram)](LICENSE) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/Silmathoron/mpl_chord_diagram) ![PyPI](https://img.shields.io/pypi/v/mpl-chord-diagram)
[![License](https://img.shields.io/badge/license-MIT-green)](LICENSE) ![PyPI](https://img.shields.io/pypi/v/mpl-chord-diagram)

Python module to plot chord diagrams with [matplotlib](https://matplotlib.org).

The code is hosted on [Codeberg's Gitea](https://codeberg.org/tfardet/mpl_chord_diagram)
and mirrored on [GitHub](https://github.com/tfardet/mpl_chord_diagram).
Please raise any issue you encouter on the [issue tracker](https://codeberg.org/tfardet/mpl_chord_diagram/issues).

Note that the repository has this structure (everything is on root level) to
be able to be used more easily as a git submodule.

Expand Down Expand Up @@ -67,24 +71,33 @@ def chord_diagram(mat, names=None, order=None, width=0.1, pad=2., gap=0.03,
use_gradient : bool, optional (default: False)
Whether a gradient should be use so that chord extremities have the
same color as the arc they belong to.
chord_colors : str, RGB tuple, list, optional (default: None)
chord_colors : str, or list of colors, optional (default: None)
Specify color(s) to fill the chords differently from the arcs.
When the keyword is not used, chord colors default to the colomap given
by `colors`.
Possible values for `chord_colors` are:
* a single color or RGB tuple, e.g. "red" or ``(1, 0, 0)``; all chords
will have this color
* a list of colors, e.g. ``["red","green","blue"]``, one per node.
Each chord will get its color from its associated source node, or
from both nodes if `use_gradient` is True.
* a single color (do not use an RGB tuple, use hex format instead),
e.g. "red" or "#ff0000"; all chords will have this color
* a list of colors, e.g. ``["red", "green", "blue"]``, one per node
(in this case, RGB tuples are accepted as entries to the list).
Each chord will get its color from its associated source node, or
from both nodes if `use_gradient` is True.
show : bool, optional (default: False)
Whether the plot should be displayed immediately via an automatic call
to `plt.show()`.
**kwargs : keyword arguments
Available kwargs are "fontsize" and "sort" (either "size" or
"distance"), "zero_entry_size" (in degrees, default: 0.5),
"rotate_names" (a bool or list of bools) to rotate (some of) the
names by 90°.
kwargs : keyword arguments
Available kwargs are:
================ ================== ===============================
Name Type Purpose and possible values
================ ================== ===============================
fontcolor str or list Color of the names
fontsize int Size of the font for names
rotate_names (list of) bool(s) Rotate names by 90°
sort str Either "size" or "distance"
zero_entry_size float Size of zero-weight reciprocal
================ ================== ===============================
"""
```

Expand Down
6 changes: 1 addition & 5 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,5 @@
Tools to draw a chord diagram in Python, using matplotlib.
"""

from ._info import __author__, __version__
from .chord_diagram import chord_diagram


__version__ = "0.2.0"

__author__ = "Tanguy Fardet"
3 changes: 3 additions & 0 deletions _info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__version__ = "0.3.0"

__author__ = "Tanguy Fardet"
42 changes: 30 additions & 12 deletions chord_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,33 @@ def chord_diagram(mat, names=None, order=None, width=0.1, pad=2., gap=0.03,
use_gradient : bool, optional (default: False)
Whether a gradient should be use so that chord extremities have the
same color as the arc they belong to.
chord_colors : str, RGB tuple, list, optional (default: None)
chord_colors : str, or list of colors, optional (default: None)
Specify color(s) to fill the chords differently from the arcs.
When the keyword is not used, chord colors default to the colomap given
by `colors`.
Possible values for `chord_colors` are:
* a single color or RGB tuple, e.g. "red" or ``(1, 0, 0)``; all chords
will have this color
* a list of colors, e.g. ``["red","green","blue"]``, one per node.
Each chord will get its color from its associated source node, or
from both nodes if `use_gradient` is True.
* a single color (do not use an RGB tuple, use hex format instead),
e.g. "red" or "#ff0000"; all chords will have this color
* a list of colors, e.g. ``["red", "green", "blue"]``, one per node
(in this case, RGB tuples are accepted as entries to the list).
Each chord will get its color from its associated source node, or
from both nodes if `use_gradient` is True.
show : bool, optional (default: False)
Whether the plot should be displayed immediately via an automatic call
to `plt.show()`.
**kwargs : keyword arguments
Available kwargs are "fontsize" and "sort" (either "size" or
"distance"), "zero_entry_size" (in degrees, default: 0.5),
"rotate_names" (a bool or list of bools) to rotate (some of) the
names by 90°.
kwargs : keyword arguments
Available kwargs are:
================ ================== ===============================
Name Type Purpose and possible values
================ ================== ===============================
fontcolor str or list Color of the names
fontsize int Size of the font for names
rotate_names (list of) bool(s) Rotate names by 90°
sort str Either "size" or "distance"
zero_entry_size float Size of zero-weight reciprocal
================ ================== ===============================
"""
import matplotlib.pyplot as plt

Expand Down Expand Up @@ -132,10 +141,18 @@ def chord_diagram(mat, names=None, order=None, width=0.1, pad=2., gap=0.03,
if colors is None:
colors = np.linspace(0, 1, num_nodes)

fontcolor = kwargs.get("fontcolor", "k")

if isinstance(fontcolor, str):
fontcolor = [fontcolor]*num_nodes
else:
assert len(fontcolor) == num_nodes, \
"One fontcolor per node is required."

if cmap is None:
cmap = "viridis"

if isinstance(colors, (Sequence, np.ndarray)):
if isinstance(colors, (list, tuple, np.ndarray)):
assert len(colors) == num_nodes, "One color per node is required."

# check color type
Expand Down Expand Up @@ -260,6 +277,7 @@ def chord_diagram(mat, names=None, order=None, width=0.1, pad=2., gap=0.03,
for i, (pos, name, r) in enumerate(zip(nodePos, names, rotation)):
rotate = rotate_names[i]
pp = prop.copy()
pp["color"] = fontcolor[i]

if rotate:
angle = np.average(arc[i])
Expand Down
3 changes: 2 additions & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
cclrs = (None, None, "slategrey", None) # chord colors
nrota = (False, False, True, True) # name rotation
cmaps = (None, None, None, "summer") # colormap
fclrs = "grey" # fontcolors

for grd, gap, srt, cc, nr, cm in zip(grads, gaps, sorts, cclrs, nrota, cmaps):
chord_diagram(flux, names, gap=gap, use_gradient=grd, sort=srt,
cmap=cm, chord_colors=cc, rotate_names=nr)
cmap=cm, chord_colors=cc, rotate_names=nr, fontcolor=fclrs)

str_grd = "_gradient" if grd else ""

Expand Down
Binary file modified images/example_gradient_sort-distance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/example_gradient_sort-size.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/example_sort-distance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/example_sort-size.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
raise


from _info import __version__


# move important files
move = (
'__init__.py',
'_info.py',
'LICENSE',
'chord_diagram.py',
'gradient.py',
Expand All @@ -32,8 +36,6 @@
print(e)


from mpl_chord_diagram import __version__

long_descr = '''
The module enables to plot chord diagrams with matplotlib from lists,
numpy or scipy sparse matrices.
Expand All @@ -58,7 +60,7 @@
install_requires = ['numpy', 'scipy', 'matplotlib'],

# Metadata
url = 'https://github.com/Silmathoron/mpl_chord_diagram',
url = 'https://codeberg.org/tfardet/mpl_chord_diagram',
author = 'Tanguy Fardet',
author_email = '[email protected]',
license = 'MIT',
Expand Down

0 comments on commit f25f27e

Please sign in to comment.