Skip to content
Permalink
Browse files

update corrplot to delay import

  • Loading branch information...
sdpython committed Nov 8, 2015
1 parent 2395920 commit be2b3bdf830ed1814346b0f55f1ce4103e3cbae6
Showing with 10 additions and 7 deletions.
  1. +1 −1 setup.py
  2. +9 −6 src/pyensae/graph_helper/corrplot.py
@@ -180,7 +180,7 @@ def write_version():
packages=packages,
package_dir=package_dir,
package_data=package_data,
install_requires=["pyquickhelper", "colormap", "qgrid", "easydev"],
install_requires=["pyquickhelper", "qgrid"],
extras_require={
'graph_helper': ['matplotlib'],
'languages': ['antlr4-python3-runtime'],
@@ -10,7 +10,6 @@
:references: http://cran.r-project.org/web/packages/corrplot/vignettes/corrplot-intro.html
"""
from .linkage import Linkage
from colormap import cmap_builder
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse, Circle, Rectangle, Wedge
@@ -44,6 +43,7 @@ class Corrplot(Linkage):
c.plot()
plt.show()
This class requires module `colormap <https://pypi.python.org/pypi/colormap>`_.
"""

def __init__(self, data, na=0):
@@ -69,8 +69,11 @@ def __init__(self, data, na=0):
"""
super(Corrplot, self).__init__()
#: The input data is stored in a dataframe and must therefore be
#: compatible (list of lists, dictionary, matrices...)

# we delay import in case this is not needed
from colormap import cmap_builder
self.cmap_builder = cmap_builder

self.df = pd.DataFrame(data, copy=True)

compute_correlation = False
@@ -98,7 +101,7 @@ def __init__(self, data, na=0):
'colorbar.orientation': 'vertical'}

def _set_default_cmap(self):
self.cm = cmap_builder('#AA0000', 'white', 'darkblue')
self.cm = self.cmap_builder('#AA0000', 'white', 'darkblue')

def order(self, method='complete', metric='euclidean', inplace=False):
"""
@@ -185,9 +188,9 @@ def plot(self, fig=None, grid=True,
if cmap is not None:
try:
if isinstance(cmap, str):
self.cm = cmap_builder(cmap)
self.cm = self.cmap_builder(cmap)
else:
self.cm = cmap_builder(*cmap)
self.cm = self.cmap_builder(*cmap)
except:
print("incorrect cmap. Use default one")
self._set_default_cmap()

0 comments on commit be2b3bd

Please sign in to comment.
You can’t perform that action at this time.