Skip to content

Commit

Permalink
Multiple plotting backends
Browse files Browse the repository at this point in the history
Merge pull request #65 from mmaelicke/plotting-backend
  • Loading branch information
mmaelicke authored Feb 8, 2021
2 parents 58a90df + 784b929 commit a2c694f
Show file tree
Hide file tree
Showing 21 changed files with 1,234 additions and 391 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[run]
omit =
skgstat/tests/*
skgstat/plotting/*
docs/*
setup.py

Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,7 @@ docs/_build
docs/savefig
notebooks
.vscode
container
container

# project specific
Playground.ipynb
4 changes: 3 additions & 1 deletion requirements.unittest.3.5.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pytest
pytest-cov
pytest-depends
pykrige
gstools==1.1.*
gstools==1.1.*
plotly
4 changes: 3 additions & 1 deletion requirements.unittest.3.6.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pytest
pytest-cov
pytest-depends
pykrige
gstools
gstools
plotly
4 changes: 3 additions & 1 deletion requirements.unittest.3.7.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pytest
pytest-cov
pytest-depends
pykrige
gstools
gstools
plotly
4 changes: 3 additions & 1 deletion requirements.unittest.3.8.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pytest
pytest-cov
pytest-depends
pykrige
gstools
gstools
plotly
55 changes: 8 additions & 47 deletions skgstat/DirectionalVariogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import matplotlib.collections

from .Variogram import Variogram
from skgstat import plotting


class DirectionalVariogram(Variogram):
Expand Down Expand Up @@ -551,7 +552,7 @@ def _direction_mask(self, force=False):
self._direction_mask_cache = self._directional_model(self._angles, self._euclidean_dist)
return self._direction_mask_cache

def pair_field(self, ax=None, cmap="gist_rainbow", points='all',add_points=True, alpha=0.3): # pragma: no cover
def pair_field(self, ax=None, cmap="gist_rainbow", points='all', add_points=True, alpha=0.3, **kwargs): # pragma: no cover
"""
Plot a pair field.
Expand All @@ -576,53 +577,13 @@ def pair_field(self, ax=None, cmap="gist_rainbow", points='all',add_points=True,
visualize better. Defaults to ``0.3``.
"""
# get the direction mask
mask = squareform(self._direction_mask())

# build a coordinate meshgrid
r = np.arange(len(self._X))
x1, x2 = np.meshgrid(r, r)
start = self._X[x1[mask]]
end = self._X[x2[mask]]

# handle lesser points
if isinstance(points, int):
points = [points]
if isinstance(points, list):
_start, _end = list(), list()
for p in self._X[points]:
_start.extend(start[np.where(end == p)[0]])
_end.extend(end[np.where(end == p)[0]])
start = np.array(_start)
end = np.array(_end)

# extract all lines and align colors
lines = np.column_stack((start.reshape(len(start), 1, 2), end.reshape(len(end), 1, 2)))
#colors = plt.cm.get_cmap(cmap)(x2[mask] / x2[mask].max())
colors = plt.cm.get_cmap(cmap)(np.linspace(0, 1, len(lines)))
colors[:, 3] = alpha

# get the figure and ax object
if ax is None:
fig, ax = plt.subplots(1, 1, figsize=(8,8))
else:
fig = ax.get_figure()

# plot
lc = matplotlib.collections.LineCollection(lines, colors=colors, linewidths=1)
ax.add_collection(lc)

# add coordinates
if add_points:
ax.scatter(self._X[:, 0], self._X[:, 1], 15, c='k')
if isinstance(points, list):
ax.scatter(self._X[:, 0][points], self._X[:, 1][points], 25, c='r')

# finish plot
ax.autoscale()
ax.margins(0.1)
# get the backend
used_backend = plotting.backend()

return fig
if used_backend == 'matplotlib':
return plotting.matplotlib_pair_field(self, ax=ax, cmap=cmap, points=points, add_points=add_points, alpha=alpha, **kwargs)
elif used_backend == 'plotly':
return plotting.plotly_pair_field(self, fig=ax, points=points, add_points=add_points, alpha=alpha, **kwargs)

def _triangle(self, angles, dists):
r"""Triangular Search Area
Expand Down
Loading

0 comments on commit a2c694f

Please sign in to comment.