Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use contourpy for Bokeh contour plots #2104

Merged
merged 13 commits into from
Sep 8, 2022
14 changes: 10 additions & 4 deletions arviz/plots/backends/bokeh/kdeplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from collections.abc import Callable
from numbers import Integral

from matplotlib import _contour
import numpy as np
from bokeh.models import ColumnDataSource
from bokeh.models.glyphs import Scatter
Expand Down Expand Up @@ -151,6 +150,11 @@ def plot_kde(
glyphs.append(line)

else:
try:
import contourpy
except ImportError as err:
raise ImportError("Install contourpy package to enable contour plots.") from err
ahartikainen marked this conversation as resolved.
Show resolved Hide resolved

contour_kwargs = _init_kwargs_dict(contour_kwargs)
contourf_kwargs = _init_kwargs_dict(contourf_kwargs)
pcolormesh_kwargs = _init_kwargs_dict(pcolormesh_kwargs)
Expand All @@ -162,8 +166,10 @@ def plot_kde(

scaled_density, *scaled_density_args = _scale_axis(density)

contour_generator = _contour.QuadContourGenerator(
x_x, y_y, scaled_density, None, True, 0
contourpy_kwargs = _init_kwargs_dict(contour_kwargs.pop("contourpy_kwargs", {}))
contourpy_kwargs.setdefault("name", "serial")
contour_generator = contourpy.contour_generator(
x=x_x, y=y_y, z=scaled_density, **contourpy_kwargs
)

levels = 9
Expand Down Expand Up @@ -199,7 +205,7 @@ def plot_kde(
contour_kwargs_ = contour_kwargs.copy()
contour_kwargs_.setdefault("line_color", color)
contour_kwargs_.setdefault("fill_color", color)
vertices, _ = contour_generator.create_filled_contour(level, level_upper)
vertices, _ = contour_generator.filled(level, level_upper)
for seg in vertices:
# ax.multi_polygon would be better, but input is
# currently not suitable
Expand Down
1 change: 1 addition & 0 deletions requirements-optional.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
numba
bokeh>=1.4.0,<3.0
contourpy
ujson
dask[distributed]
zarr>=2.5.0