# Path: contact_map/plot_utils.py
# def ranged_colorbar(cmap, norm, cbmin, cbmax, ax=None):
#     """Create a colorbar with given endpoints.
# 
#     Parameters
#     ----------
#     cmap : str or matplotlib.colors.Colormap
#         the base colormap to use
#     norm : matplotlib.colors.Normalize
#         the normalization (range of values) used in the image
#     cbmin : float
#         minimum value for the colorbar
#     cbmax : float
#         maximum value for the colorbar
#     ax : matplotlib.Axes
#         the axes to take space from to plot the colorbar
# 
#     Returns
#     -------
#     matplotlib.colorbar.Colorbar
#         a colorbar restricted to the range given by cbmin, cbmax
#     """
#     # see https://stackoverflow.com/questions/24746231
#     if isinstance(cmap, str):
#         cmap_f = plt.get_cmap(cmap)
#     else:
#         cmap_f = cmap
# 
#     if ax is None:
#         fig = plt
#     else:
#         fig = ax.figure
# 
#     cbmin_normed = float(cbmin - norm.vmin) / (norm.vmax - norm.vmin)
#     cbmax_normed = float(cbmax - norm.vmin) / (norm.vmax - norm.vmin)
#     n_colors = int(round((cbmax_normed - cbmin_normed) * cmap_f.N))
#     colors = cmap_f(np.linspace(cbmin_normed, cbmax_normed, n_colors))
#     new_cmap = LinearSegmentedColormap.from_list(name="Partial Map",
#                                                  colors=colors)
#     new_norm = matplotlib.colors.Normalize(vmin=cbmin, vmax=cbmax)
#     sm = plt.cm.ScalarMappable(cmap=new_cmap, norm=new_norm)
#     sm._A = []
#     cb = fig.colorbar(sm, ax=ax, fraction=0.046, pad=0.04)
#     return cb
# 
# def make_x_y_ranges(n_x, n_y, counter):
#     """Return ContactPlotRange for both x and y"""
#     n_x, n_y = _sanitize_n_x_n_y(n_x, n_y, counter)
#     n_x = _ContactPlotRange(n_x)
#     n_y = _ContactPlotRange(n_y)
#     return n_x, n_y
# 
# def is_cmap_diverging(cmap):
#     if cmap in _DIVERGING:
#         return True
#     elif cmap in _SEQUENTIAL:
#         return False
#     else:
#         warnings.warn("Unknown colormap: Treating as sequential.")
#         return False


import collections
import scipy
import numpy as np
import pandas as pd
import warnings
    import matplotlib
    import matplotlib.pyplot as plt
    import networkx as nx
from .plot_utils import ranged_colorbar, make_x_y_ranges, is_cmap_diverging
from pandas._libs.sparse import BlockIndex, IntIndex, SparseIndex

# matplotlib is technically optional, but required for plotting
try:
except ImportError:
    HAS_MATPLOTLIB = False
else:
    HAS_MATPLOTLIB = True

try:
except ImportError:
    HAS_NETWORKX = False
else:
    HAS_NETWORKX = True

# pandas 0.25 not available on py27; can drop this when we drop py27
_PD_VERSION = tuple(int(x) for x in pd.__version__.split('.')[:2])


def _colorbar(with_colorbar, cmap_f, norm, min_val, ax=None):
    if with_colorbar is False:
        return None
    elif with_colorbar is True:
        cbmin = np.floor(min_val)  # [-1.0..0.0] => -1; [0.0..1.0] => 0
        cbmax = 1.0

# Path: contact_map/plot_utils.py
# def ranged_colorbar(cmap, norm, cbmin, cbmax, ax=None):
#     """Create a colorbar with given endpoints.
# 
#     Parameters
#     ----------
#     cmap : str or matplotlib.colors.Colormap
#         the base colormap to use
#     norm : matplotlib.colors.Normalize
#         the normalization (range of values) used in the image
#     cbmin : float
#         minimum value for the colorbar
#     cbmax : float
#         maximum value for the colorbar
#     ax : matplotlib.Axes
#         the axes to take space from to plot the colorbar
# 
#     Returns
#     -------
#     matplotlib.colorbar.Colorbar
#         a colorbar restricted to the range given by cbmin, cbmax
#     """
#     # see https://stackoverflow.com/questions/24746231
#     if isinstance(cmap, str):
#         cmap_f = plt.get_cmap(cmap)
#     else:
#         cmap_f = cmap
# 
#     if ax is None:
#         fig = plt
#     else:
#         fig = ax.figure
# 
#     cbmin_normed = float(cbmin - norm.vmin) / (norm.vmax - norm.vmin)
#     cbmax_normed = float(cbmax - norm.vmin) / (norm.vmax - norm.vmin)
#     n_colors = int(round((cbmax_normed - cbmin_normed) * cmap_f.N))
#     colors = cmap_f(np.linspace(cbmin_normed, cbmax_normed, n_colors))
#     new_cmap = LinearSegmentedColormap.from_list(name="Partial Map",
#                                                  colors=colors)
#     new_norm = matplotlib.colors.Normalize(vmin=cbmin, vmax=cbmax)
#     sm = plt.cm.ScalarMappable(cmap=new_cmap, norm=new_norm)
#     sm._A = []
#     cb = fig.colorbar(sm, ax=ax, fraction=0.046, pad=0.04)
#     return cb
# 
# def make_x_y_ranges(n_x, n_y, counter):
#     """Return ContactPlotRange for both x and y"""
#     n_x, n_y = _sanitize_n_x_n_y(n_x, n_y, counter)
#     n_x = _ContactPlotRange(n_x)
#     n_y = _ContactPlotRange(n_y)
#     return n_x, n_y
# 
# def is_cmap_diverging(cmap):
#     if cmap in _DIVERGING:
#         return True
#     elif cmap in _SEQUENTIAL:
#         return False
#     else:
#         warnings.warn("Unknown colormap: Treating as sequential.")
#         return False


# Path: contact_map/contact_count.py
import collections
import scipy
import numpy as np
import pandas as pd
import warnings
    import matplotlib
    import matplotlib.pyplot as plt
    import networkx as nx
from .plot_utils import ranged_colorbar, make_x_y_ranges, is_cmap_diverging
from pandas._libs.sparse import BlockIndex, IntIndex, SparseIndex


# matplotlib is technically optional, but required for plotting
try:
except ImportError:
    HAS_MATPLOTLIB = False
else:
    HAS_MATPLOTLIB = True

try:
except ImportError:
    HAS_NETWORKX = False
else:
    HAS_NETWORKX = True

# pandas 0.25 not available on py27; can drop this when we drop py27
_PD_VERSION = tuple(int(x) for x in pd.__version__.split('.')[:2])


def _colorbar(with_colorbar, cmap_f, norm, min_val, ax=None):
    if with_colorbar is False:
        return None
    elif with_colorbar is True:
        cbmin = np.floor(min_val)  # [-1.0..0.0] => -1; [0.0..1.0] => 0
        cbmax = 1.0

        cb = ranged_colorbar(cmap_f, norm, cbmin, cbmax, ax=ax)