Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
replace axisgb by facecolor
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Feb 21, 2017
1 parent 1d95528 commit 07da584
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 88 deletions.
174 changes: 92 additions & 82 deletions _doc/notebooks/example_corrplot.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _unittests/ut_graph/test_corrplot.py
Expand Up @@ -68,7 +68,7 @@ def test_graph_corrplot(self):
df = df.corr()

fig = plt.figure(num=None, facecolor='white')
ax = plt.subplot(1, 1, 1, aspect='equal', axisbg='white')
ax = plt.subplot(1, 1, 1, aspect='equal', facecolor='white')

c = Corrplot(df)
ax = c.plot(fig=fig, ax=ax)
Expand Down
15 changes: 10 additions & 5 deletions src/pyensae/graph_helper/corrplot.py
Expand Up @@ -9,12 +9,20 @@
:author: Thomas Cokelaer
:references: http://cran.r-project.org/web/packages/corrplot/vignettes/corrplot-intro.html
"""
from .linkage import Linkage
try:
from scipy.cluster.hierarchy import dendrogram, fcluster
except ImportError as e:
# The import of scipy was moved it. It creates a warning otherwise.
# lib\importlib\_bootstrap.py:205: ImportWarning: can't resolve package
# from __spec__ or __package__, falling back on __name__ and __path__
import warnings
warnings.warn("corrplot.py requires scipy.")
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse, Circle, Rectangle, Wedge
from matplotlib.collections import PatchCollection
import pandas as pd
from .linkage import Linkage


class Corrplot(Linkage):
Expand Down Expand Up @@ -87,7 +95,6 @@ def __init__(self, data, na=0):
compute_correlation = True

if compute_correlation:
print("Computing correlation")
cor = self.df.corr()
self.df = cor

Expand Down Expand Up @@ -116,7 +123,6 @@ def order(self, method='complete', metric='euclidean', inplace=False):
You probably do not need to use that method. Use :meth:`plot` and
the two parameters order_metric and order_method instead.
"""
from scipy.cluster.hierarchy import fcluster, dendrogram
Y = self.linkage(self.df, method=method, metric=metric)
ind1 = fcluster(Y, 0.7 * max(Y[:, 2]), 'distance')
Z = dendrogram(Y, no_plot=True)
Expand Down Expand Up @@ -192,7 +198,6 @@ def plot(self, fig=None, grid=True,
else:
self.cm = self.cmap_builder(*cmap)
except Exception:
print("incorrect cmap. Use default one")
self._set_default_cmap()
else:
self._set_default_cmap()
Expand All @@ -217,7 +222,7 @@ def plot(self, fig=None, grid=True,

# do we have an axes to plot the data in ?
if ax is None:
ax = plt.subplot(1, 1, 1, aspect='equal', axisbg=axisbg)
ax = plt.subplot(1, 1, 1, aspect='equal', facecolor=axisbg)
else:
# if so, clear the axes. Colorbar cannot be removed easily.
plt.sca(ax)
Expand Down

0 comments on commit 07da584

Please sign in to comment.