def _scatterhist_help( axes=None, top_height=0, left_width=0, right_width=0, bottom_height=0, ): """Create a scatter plot with the marginal distribution for `x` plotted in a separate pain as a kernel density estimate. Parameters ---------- color : matplotlib colorspec, or None, optional Color to plot data series axes : :class:`matplotlib.axes.Axes`, dict, or `None`, optional If a :class:`matplotlib.axes.Axes`, an axes in which to place plot. This axes will be split into relevant panels. If a dict, this is expected to be a group of pre-split axes. If `None`, a new figure is generated, and axes are split. (Default: `None`) top_height, left_width, right_width, bottom_height : float, optional If not `None`, a panel on the corresponding side of the `ax` will be created, using whatever fraction is specified (e.g. 0.1 to use 10% of total height). Returns ------- :class:`matplotlib.figure.Figure` Parent figure of axes dict of :class:`matplotlib.axes.Axes` axes containing plot space """ if axes is None: fig = plt.figure() axes = plt.gca() if isinstance(axes, matplotlib.axes.Axes): fig = axes.figure axes = split_axes(axes, top_height=top_height, left_width=left_width, right_width=right_width, bottom_height=bottom_height) elif isinstance(axes, dict): fig = axes["main"].figure if left_width > 0: assert "left" in axes if right_width > 0: assert "right" in axes if bottom_height > 0: assert "bottom" in axes if top_height > 0: assert "top" in axes return fig, axes
def _scatterhist_help(axes=None, top_height=0,left_width=0,right_width=0,bottom_height=0, ): """Create a scatter plot with the marginal distribution for `x` plotted in a separate pain as a kernel density estimate. Parameters ---------- color : matplotlib colorspec, or None, optional Color to plot data series axes : :class:`matplotlib.axes.Axes`, dict, or `None`, optional If a :class:`matplotlib.axes.Axes`, an axes in which to place plot. This axes will be split into relevant panels. If a dict, this is expected to be a group of pre-split axes. If `None`, a new figure is generated, and axes are split. (Default: `None`) top_height, left_width, right_width, bottom_height : float, optional If not `None`, a panel on the corresponding side of the `ax` will be created, using whatever fraction is specified (e.g. 0.1 to use 10% of total height). Returns ------- :class:`matplotlib.figure.Figure` Parent figure of axes dict of :class:`matplotlib.axes.Axes` axes containing plot space """ if axes is None: fig = plt.figure() axes = plt.gca() if isinstance(axes,matplotlib.axes.Axes): fig = axes.figure axes = split_axes(axes,top_height=top_height,left_width=left_width, right_width=right_width,bottom_height=bottom_height) elif isinstance(axes,dict): fig = axes["main"].figure if left_width > 0: assert "left" in axes if right_width > 0: assert "right" in axes if bottom_height > 0: assert "bottom" in axes if top_height > 0: assert "top" in axes return fig, axes
def profile_heatmap(data, profile=None, x=None, axes=None, sort_fn=sort_max_position, cmap=None, nancolor="#666666", im_args={}, plot_args={}): """Create a dual-paned plot in which `profile` is displayed in a top panel, above a heatmap showing the intensities of each row of `data`, optionally sorted top-to-bottom by `sort_fn`. Parameters ---------- data : :class:`numpy.ndarray` Array of data, in which each row is an individual aligned vector of data for region of interest, and each column a position in that vector profile : :class:`numpy.ndarray` or None Reduced profile of data, often a column-wise median. If not supplied, it will be calculated. x : :class:`numpy.ndarray` Array of values for X-axis axes : :class:`matplotlib.axes.Axes` or `None`, optional Axes in which to place plot. If `None`, a new figure is generated. (Default: `None`) sort_fn : function, optional Sort rows in `data` by this function before plotting. Function must return a :class:`numpy.ndarray` of indices corresponding to rows in `data` (Default: sort by ascending argmax of each row) cmap : :class:`~matplotlib.colors.Colormap`, optional Colormap to use in heatmap. It not `None`, overrides any value in `im_args`. (Default: `None`) nancolor : str or matplotlib colorspec Color used for plotting `nan` and other illegal or masked values im_args : dict Keyword arguments to pass to :func:`matplotlib.pyplot.imshow` plot_args : dict Keyword arguments to pass to :func:`matplotlib.pyplot.plot` for plotting metagene average Returns ------- :class:`matplotlib.figure.Figure` Parent figure of axes dict Dictionary of :class:`matplotlib.axes.Axes`. "top" refers to the panel containing the summary profile. "main" refers to the heatmap of individual values """ fig, ax = get_fig_axes(axes) axes = split_axes(ax, top_height=0.2) if sort_fn is None: sort_indices = numpy.arange(data.shape[0]) else: sort_indices = sort_fn(data) if x is None: x = numpy.arange(0, data.shape[1]) if profile is None: profile = numpy.nanmedian(data, axis=0) im_args = copy.deepcopy(im_args) # populate with defaults for k, v in _heatmap_defaults.items(): if k not in im_args: im_args[k] = v if "extent" not in im_args: im_args["extent"] = [x.min(), x.max(), 0, data.shape[0]] #,0] if "vmin" not in im_args: im_args["vmin"] = numpy.nanmin(data) if "vmax" not in im_args: im_args["vmax"] = numpy.nanmax(data) if cmap is not None: im_args["cmap"] = cmap elif "cmap" in im_args: cmap = matplotlib.cm.get_cmap(im_args["cmap"]) else: cmap = matplotlib.cm.get_cmap() cmap.set_bad(nancolor, 1.0) axes["top"].plot(x, profile, **plot_args) axes["top"].set_ylim(0, profile.max()) axes["top"].set_xlim(x.min(), x.max()) #axes["top"].set_yticks([]) axes["top"].set_yticks([0, profile.max()]) axes["top"].xaxis.tick_bottom() axes["top"].grid(True, which="both") axes["main"].xaxis.tick_bottom() axes["main"].imshow(data[sort_indices, :], **im_args) return fig, axes
def profile_heatmap(data,profile=None,x=None,axes=None,sort_fn=sort_max_position, cmap=None,nancolor="#666666",im_args={},plot_args={}): """Create a dual-paned plot in which `profile` is displayed in a top panel, above a heatmap showing the intensities of each row of `data`, optionally sorted top-to-bottom by `sort_fn`. Parameters ---------- data : :class:`numpy.ndarray` Array of data, in which each row is an individual aligned vector of data for region of interest, and each column a position in that vector profile : :class:`numpy.ndarray` or None Reduced profile of data, often a column-wise median. If not supplied, it will be calculated. x : :class:`numpy.ndarray` Array of values for X-axis axes : :class:`matplotlib.axes.Axes` or `None`, optional Axes in which to place plot. If `None`, a new figure is generated. (Default: `None`) sort_fn : function, optional Sort rows in `data` by this function before plotting. Function must return a :class:`numpy.ndarray` of indices corresponding to rows in `data` (Default: sort by ascending argmax of each row) cmap : :class:`~matplotlib.colors.Colormap`, optional Colormap to use in heatmap. It not `None`, overrides any value in `im_args`. (Default: `None`) nancolor : str or matplotlib colorspec Color used for plotting `nan` and other illegal or masked values im_args : dict Keyword arguments to pass to :func:`matplotlib.pyplot.imshow` plot_args : dict Keyword arguments to pass to :func:`matplotlib.pyplot.plot` for plotting metagene average Returns ------- :class:`matplotlib.figure.Figure` Parent figure of axes dict Dictionary of :class:`matplotlib.axes.Axes`. "top" refers to the panel containing the summary profile. "main" refers to the heatmap of individual values """ fig, ax = get_fig_axes(axes) axes = split_axes(ax,top_height=0.2) if sort_fn is None: sort_indices = numpy.arange(data.shape[0]) else: sort_indices = sort_fn(data) if x is None: x = numpy.arange(0,data.shape[1]) if profile is None: profile = numpy.nanmedian(data,axis=0) im_args = copy.deepcopy(im_args) # populate with defaults for k,v in _heatmap_defaults.items(): if k not in im_args: im_args[k] = v if "extent" not in im_args: im_args["extent"] = [x.min(),x.max(),0,data.shape[0]]#,0] if "vmin" not in im_args: im_args["vmin"] = numpy.nanmin(data) if "vmax" not in im_args: im_args["vmax"] = numpy.nanmax(data) if cmap is not None: im_args["cmap"] = cmap elif "cmap" in im_args: cmap = matplotlib.cm.get_cmap(im_args["cmap"]) else: cmap = matplotlib.cm.get_cmap() cmap.set_bad(nancolor,1.0) axes["top"].plot(x,profile,**plot_args) axes["top"].set_ylim(0,profile.max()) axes["top"].set_xlim(x.min(),x.max()) #axes["top"].set_yticks([]) axes["top"].set_yticks([0,profile.max()]) axes["top"].xaxis.tick_bottom() axes["top"].grid(True,which="both") axes["main"].xaxis.tick_bottom() axes["main"].imshow(data[sort_indices,:],**im_args) return fig, axes