Skip to content

Commit

Permalink
Make package for pypi (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Silmathoron authored Sep 2, 2020
1 parent 1261852 commit 2844e77
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 26 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# python stuff
*.pyc
*/__pycache__
build/
dist/
mpl_chord_diagram.egg-info/
6 changes: 6 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Include the license file
include LICENSE
include Readme.md

# include setup.py
include setup.py
48 changes: 28 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@

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

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

## Usage and requirements

Add the module to your ``PYTHONPATH``, then, in python script or terminal:
Install using

pip install mpl-chord-diagram

then, in python script or terminal:

```python
from mpl_chord_diagram import chord_diagram
```

If you don't know how to change the ``PYTHONPATH``, use the ``example.py``
file, it provides a workaround.

The code requires ``numpy``, ``scipy`` and ``matplotlib``, you can install
them by calling
The code requires ``numpy``, ``scipy`` and ``matplotlib``, which should be
installed automatically. If necessary, you can also install them by calling

pip install -r requirements.txt
pip install -r requirements.txt


## Main plot function
Expand Down Expand Up @@ -66,35 +69,40 @@ An example can be found in file `example.py`.
Here is what the diagrams look like (with and without gradient and gap,
up and down are sorted respectively by domain size and distance):

<img src="example_sort-size.png" width="390"
<img src="images/example_sort-size.png" width="390"
alt="Chord diagram without gradient, sorted by size"><img
src="example_gradient_sort-size.png" width="390"
src="images/example_gradient_sort-size.png" width="390"
alt="Chord diagram without gradient, sorted by size">

<img src="example_sort-distance.png" width="390"
<img src="images/example_sort-distance.png" width="390"
alt="Chord diagram without gradient, sorted by distance"><img
src="example_gradient_sort-distance.png" width="390"
src="images/example_gradient_sort-distance.png" width="390"
alt="Chord diagram without gradient, dorted by distance">


## Contributors

* Original author: [@fengwangPhysics](https://github.com/fengwangPhysics)
* Refactoring (Tanguy Fardet, PRs
[#6](https://github.com/Silmathoron/matplotlib-chord-diagram/pull/6) &
[#9](https://github.com/Silmathoron/matplotlib-chord-diagram/pull/9))
[#6](https://github.com/Silmathoron/mpl_chord_diagram/pull/6),
[#9](https://github.com/Silmathoron/mpl_chord_diagram/pull/9) &
[#12](https://github.com/Silmathoron/mpl_chord_diagram/pull/12))
* Support sparse matrices: Tanguy Fardet (PR
[#10](https://github.com/Silmathoron/mpl_chord_diagram/pull/10))
* Improved color support:
- [@pakitochus](https://github.com/pakitochus) (PR [#1](https://github.com/Silmathoron/matplotlib-chord-diagram/pull/1))
- [@pakitochus](https://github.com/pakitochus) (PR
[#1](https://github.com/Silmathoron/mpl_chord_diagram/pull/1))
- Tanguy Fardet (PRs
[#4](https://github.com/Silmathoron/matplotlib-chord-diagram/pull/4) for
[#4](https://github.com/Silmathoron/mpl_chord_diagram/pull/4) for
colors/colormaps and
[#5](https://github.com/Silmathoron/matplotlib-chord-diagram/pull/5) &
[#7](https://github.com/Silmathoron/matplotlib-chord-diagram/pull/7) for
[#5](https://github.com/Silmathoron/mpl_chord_diagram/pull/5) &
[#7](https://github.com/Silmathoron/mpl_chord_diagram/pull/7) for
gradients)
* Improved arcs:
- [@cy1110](https://github.com/cy1110) (PR [#2](https://github.com/Silmathoron/matplotlib-chord-diagram/pull/2))
- [@cy1110](https://github.com/cy1110) (PR
[#2](https://github.com/Silmathoron/mpl_chord_diagram/pull/2))
- Tanguy Fardet (PRs
[#6](https://github.com/Silmathoron/matplotlib-chord-diagram/pull/6) for
[#6](https://github.com/Silmathoron/mpl_chord_diagram/pull/6) for
gap addition and
[#7](https://github.com/Silmathoron/matplotlib-chord-diagram/pull/7) for
[#7](https://github.com/Silmathoron/mpl_chord_diagram/pull/7) for
adaptive curvature and sorting)
5 changes: 5 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
"""

from .chord_diagram import chord_diagram


__version__ = "0.1.0"

__author__ = "Tanguy Fardet"
2 changes: 1 addition & 1 deletion chord_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
LW = 0.3


def chord_diagram(mat, names=None, width=0.1, pad=2., gap=0., chordwidth=0.7,
def chord_diagram(mat, names=None, width=0.1, pad=2., gap=0.03, chordwidth=0.7,
ax=None, colors=None, cmap=None, alpha=0.7,
use_gradient=False, show=False, **kwargs):
"""
Expand Down
13 changes: 8 additions & 5 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@

# flux matrix

flux = np.array([[11975, 5871, 8916, 2868],
[ 1951, 10048, 2060, 6171],
[ 8010, 16145, 81090, 8045],
[ 1013, 990, 940, 6907]
flux = np.array([
[11975, 5871, 8916, 2868],
[ 1951, 10048, 2060, 6171],
[ 8010, 16145, 81090, 8045],
[ 1013, 990, 940, 6907]
])

names = ['non-crystal', 'FCC', 'HCP', 'BCC']
Expand All @@ -30,8 +31,10 @@
for grd, gap, sort in zip(gradients, gaps, sorts):
chord_diagram(flux, names, gap=gap, use_gradient=grd, sort=sort)

str_grd = "_gradient" if grd else ""

plt.savefig(
"example{}_sort-{}.png".format("_gradient" if grd else "", sort),
"images/example{}_sort-{}.png".format(str_grd, sort),
dpi=600, transparent=True, bbox_inches='tight',
pad_inches=0.02)

Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[bdist_wheel]
# This flag says that the code is written to work on both Python 2 and Python
# 3. If at all possible, it is good practice to do this. If you cannot, you
# will need to generate wheels for each Python version that you support.
universal=1
84 changes: 84 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import os, errno
from setuptools import setup, find_packages


# create directory
setup_dir = os.path.abspath(os.path.dirname(__file__))
directory = setup_dir + '/mpl_chord_diagram/'

try:
os.makedirs(directory)
except OSError as e:
if e.errno != errno.EEXIST:
raise


# move important files
move = (
'__init__.py',
'LICENSE',
'chord_diagram.py',
'gradient.py',
'utilities.py',
'example.py',
)


for fname in move:
try:
os.rename(fname, directory + fname)
except Exception as e:
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.
It provides tunable parameters such as arc sorting based on size or distance,
and supports gradients to better visualize source and target regions.
'''


try:
# install
setup(
name = 'mpl_chord_diagram',
version = __version__,
description = 'Python module to plot chord diagrams with matplotlib.',
package_dir = {'': '.'},
packages = find_packages('.'),

# Include the non python files:
package_data = {'': ['LICENSE', '*.md']},

# Requirements
install_requires = ['numpy', 'scipy', 'matplotlib'],

# Metadata
url = 'https://github.com/Silmathoron/mpl_chord_diagram',
author = 'Tanguy Fardet',
author_email = '[email protected]',
license = 'MIT',
keywords = 'chord diagram matplotlib plotting',
long_description = long_descr,
classifiers = [
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 3',
'Operating System :: OS Independent',
'Topic :: Scientific/Engineering :: Visualization',
'Framework :: Matplotlib',
]
)
except:
pass
finally:
for fname in move:
try:
os.rename(directory + fname, fname)
except:
pass

0 comments on commit 2844e77

Please sign in to comment.