From 2844e774d0d87ea3c62f18db4c958e8184c9456a Mon Sep 17 00:00:00 2001 From: Tanguy Fardet Date: Wed, 2 Sep 2020 11:26:17 +0200 Subject: [PATCH] Make package for pypi (#12) --- .gitignore | 6 ++ MANIFEST.in | 6 ++ README.md | 48 +++++----- __init__.py | 5 ++ chord_diagram.py | 2 +- example.py | 13 +-- .../example_gradient_sort-distance.png | Bin .../example_gradient_sort-size.png | Bin .../example_sort-distance.png | Bin .../example_sort-size.png | Bin setup.cfg | 5 ++ setup.py | 84 ++++++++++++++++++ 12 files changed, 143 insertions(+), 26 deletions(-) create mode 100644 .gitignore create mode 100644 MANIFEST.in rename example_gradient_sort-distance.png => images/example_gradient_sort-distance.png (100%) rename example_gradient_sort-size.png => images/example_gradient_sort-size.png (100%) rename example_sort-distance.png => images/example_sort-distance.png (100%) rename example_sort-size.png => images/example_sort-size.png (100%) create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f03b3f4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# python stuff +*.pyc +*/__pycache__ +build/ +dist/ +mpl_chord_diagram.egg-info/ diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..d77370f --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,6 @@ +# Include the license file +include LICENSE +include Readme.md + +# include setup.py +include setup.py diff --git a/README.md b/README.md index 0250900..3d7b51e 100644 --- a/README.md +++ b/README.md @@ -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 @@ -66,14 +69,14 @@ 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): -Chord diagram without gradient, sorted by sizeChord diagram without gradient, sorted by size -Chord diagram without gradient, sorted by distanceChord diagram without gradient, dorted by distance @@ -81,20 +84,25 @@ up and down are sorted respectively by domain size and distance): * 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) diff --git a/__init__.py b/__init__.py index d076a15..ec62861 100644 --- a/__init__.py +++ b/__init__.py @@ -6,3 +6,8 @@ """ from .chord_diagram import chord_diagram + + +__version__ = "0.1.0" + +__author__ = "Tanguy Fardet" diff --git a/chord_diagram.py b/chord_diagram.py index 47b57f9..bdb2d9b 100644 --- a/chord_diagram.py +++ b/chord_diagram.py @@ -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): """ diff --git a/example.py b/example.py index ee41a34..52499d6 100644 --- a/example.py +++ b/example.py @@ -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'] @@ -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) diff --git a/example_gradient_sort-distance.png b/images/example_gradient_sort-distance.png similarity index 100% rename from example_gradient_sort-distance.png rename to images/example_gradient_sort-distance.png diff --git a/example_gradient_sort-size.png b/images/example_gradient_sort-size.png similarity index 100% rename from example_gradient_sort-size.png rename to images/example_gradient_sort-size.png diff --git a/example_sort-distance.png b/images/example_sort-distance.png similarity index 100% rename from example_sort-distance.png rename to images/example_sort-distance.png diff --git a/example_sort-size.png b/images/example_sort-size.png similarity index 100% rename from example_sort-size.png rename to images/example_sort-size.png diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..79bc678 --- /dev/null +++ b/setup.cfg @@ -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 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..2f2de67 --- /dev/null +++ b/setup.py @@ -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 = 'tanguy.fardet@tuebingen.mpg.de', + 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