Datashader in Matplotlib#
Datashading capabilities for hiveplotlib.
- hiveplotlib.viz.datashader.datashade_edges_mpl(instance: BaseHivePlot | HivePlot | P2CP, tag: Hashable | None = None, cmap: str | ListedColormap | None = None, vmin: float = 1, vmax: float | None = None, log_cmap: bool = True, pixel_spread: int = 1, reduction: Reduction | None = None, buffer: float = 0.1, fig: Figure | None = None, ax: Axes | None = None, figsize: Tuple[float, float] = (10, 10), dpi: int = 150, axes_off: bool = True, fig_kwargs: dict | None = None, **im_kwargs) Tuple[Figure, Axes, AxesImage | None]#
matplotlibvisualization of constructed edges in aHivePlotorP2CPinstance usingdatashader.The main idea of
datashaderis rather than plot all the lines on top of each other in a figure, one can instead essentially build up a single 2d image of the lines in 2-space. We can then plot just this rasterization, which is much smaller. By using the default reduction functionreduction=ds.count(counting values in bins), we are essentially building a 2d histogram. For more on reductions indatashader, see the datashader documentation, and for a complete list of reduction functions available, see the datashader API docs.Note
A higher
dpivalue when datashading will allow for more nuance in the rasterization, but will require adjusting thepixel_spreadparameter accordingly (larger spread likely needed when using a higherdpi).Experimentation with different (low) values for
pixel_spreadis encouraged. As the name suggests, this parameter spreads out calculated pixel values in the rasterization radially. Values that are too low tends to result in the thinner, more isolated curves “breaking apart” in the final visualization. For more on spreading, see the datashader documentation.Any provided edge plotting keyword arguments in
HivePlot.edges.edge_viz_kwargswill be disregarded in this visualization, as this flexibility is reserved for datashading the edges. Inclusion of any edge kwargs here as part of theim_kwargswill likely trigger an error.- Parameters:
instance –
HivePlotorP2CPinstance for which we want to draw edges.tag – which tag of data to plot. If
Noneis provided, then plotting will occur if there is only one tag in the instance. For more on data tags, see further discussion in the Comparing Network Subgroups Notebook.cmap – which colormap to use for the datashaded edges. Default uses a
seaborncolormap similar to thematplotlib"Blues"colormap.vmin – minimum value used in the colormap for plotting the rasterization of curves. Default 1.
vmax – maximum value used in the colormap for plotting the rasterization of curves. Default
Nonefinds and uses the maximum bin value of the calculated rasterization.log_cmap – whether to use a logarithmic (base 10) scale for the colormap. Default
True.reduction – the means of projecting from data space to pixel space for the rasterization. Default
Noneusesds.count(), essentially building a 2d histogram. For more on reductions indatashader, see the datashader documentation, and for a complete list of reduction functions available, see the datashader API docs.pixel_spread – amount of pixel units in which to “spread” pixel values in the resulting rasterization before plotting. Default amount of spreading is 1 pixel. For more on spreading, see the datashader documentation.
buffer – fraction of the axes past which to buffer x and y dimensions (e.g. setting
bufferto 0.1 will find the maximum radius spanned by anyAxisinstance and set the x and y bounds as(-max_radius - buffer * max_radius, max_radius + buffer * max_radius)).fig – default
Nonebuilds new figure. If a figure is specified,Axisinstances will be drawn on that figure. Note:figandaxmust BOTH beNoneto instantiate new figure and axes.ax – default
Nonebuilds new axis. If an axis is specified,Axisinstances will be drawn on that axis. Note:figandaxmust BOTH beNoneto instantiate new figure and axes.figsize – size of figure. Note: only works if instantiating new figure and axes (e.g.
figandaxareNone).dpi – resolution (Dots Per Inch) of resulting figure. A higher-than-usual DPI is recommended to show more pixels in the final rasterization, which will show more nuance.
axes_off – whether to turn off Cartesian x, y axes in resulting
matplotlibfigure (defaultTruehides the x and y axes).fig_kwargs – additional values to be called in
plt.subplots()call. Note iffigsizeis added here, then it will be prioritized over thefigsizeparameter.im_kwargs – additional params that will be applied to the final
plt.imshow()call on the rasterization. Must not clash with the cmap, vmin, or vmax parameters.
- Raises:
ValueError – If a column-based
reduction(e.g.ds.sum('col'),ds.mean('col'),ds.count_cat('col')) references an edge metadata column that does not exist for the selectedtag.- Returns:
matplotlibfigure, axis, image. If there are no edges to plot, the returned image will beNone.
- hiveplotlib.viz.datashader.datashade_hive_plot_mpl(instance: BaseHivePlot | HivePlot | P2CP, tag: Hashable | None = None, cmap_edges: str | ListedColormap | None = None, cmap_nodes: str | ListedColormap = 'copper', vmin_nodes: float = 1, vmax_nodes: float | None = None, vmin_edges: float = 1, vmax_edges: float | None = None, node_kwargs: dict | None = None, log_cmap_nodes: bool = True, pixel_spread_nodes: int = 7, reduction_nodes: Reduction | None = None, log_cmap_edges: bool = True, pixel_spread_edges: int = 1, reduction_edges: Reduction | None = None, fig: Figure | None = None, ax: Axes | None = None, figsize: Tuple[float, float] = (10, 10), dpi: int = 150, axes_off: bool = True, buffer: float = 0.1, show_axes_labels: bool = True, axes_labels_buffer: float = 1.1, axes_labels_fontsize: int = 16, axes_kwargs: dict | None = None, text_kwargs: dict | None = None, fig_kwargs: dict | None = None, **edge_kwargs) Tuple[Figure, Axes, AxesImage | None, AxesImage | None]#
matplotlibvisualization of aHivePlotorP2CPinstance usingdatashader.Plots both nodes and edges with datashader along with standard hive plot / P2CP axes.
The main idea of
datashaderis rather than plot all the lines on top of each other in a figure, one can instead essentially build up a single 2d image of the lines in 2-space. We can then plot just this rasterization, which is much smaller. By using the default reduction functionds.count()(counting values in bins), we are essentially building a 2d histogram. For more on reductions indatashader, see the datashader documentation, and for a complete list of reduction functions available, see the datashader API docs.Note
A higher
dpivalue when datashading will allow for more nuance in the rasterization, but will require adjusting thepixel_spread_nodesandpixel_spread_edgesparameters accordingly (larger spreads likely needed when using a higherdpi). Higherdpivalues will also increase computation time.Experimentation with different (low) values for
pixel_spread_nodesandpixel_spread_edgesis encouraged. As the name suggests, this parameter spreads out calculated pixel values in the rasterization radially. Values that are too low tends to result in the thinner, more isolated curves “breaking apart” in the final visualization. For more on spreading, see the datashader documentation.Any provided node plotting keyword arguments in
HivePlot.nodes.node_viz_kwargswill be disregarded in this visualization, as this flexibility is reserved for datashading the nodes. Inclusion of anynode_kwargshere will also raise a warning.Any provided edge plotting keyword arguments in
HivePlot.edges.edge_viz_kwargswill be disregarded in this visualization, as this flexibility is reserved for datashading the edges. Inclusion of any edge kwargs here as part of theim_kwargswill likely trigger an error.- Parameters:
instance –
HivePlotorP2CPinstance for which we want to visualize.tag – which tag of data to plot. If
Noneis provided, then plotting will occur if there is only one tag in the instance. For more on data tags, see further discussion in the Comparing Network Subgroups Notebook.cmap_edges – which colormap to use for the datashaded edges. Default uses a
seaborncolormap similar to thematplotlib"Blues"colormap.cmap_nodes – which colormap to use for the datashaded nodes. Default “copper”.
vmin_nodes – minimum value used in the colormap for plotting the rasterization of nodes. Default 1.
vmax_nodes – maximum value used in the colormap for plotting the rasterization of nodes. Default
Nonefinds and uses the maximum bin value of the calculated rasterization.vmin_edges – minimum value used in the colormap for plotting the rasterization of edges. Default 1.
vmax_edges – maximum value used in the colormap for plotting the rasterization of edges. Default
Nonefinds and uses the maximum bin value of the calculated rasterization.node_kwargs – additional params that will be applied to the final
plt.imshow()call on the edge rasterization. Must not clash with the cmap_nodes, vmin_nodes, or vmax_nodes parameters.log_cmap_nodes – whether to use a logarithmic (base 10) scale for the colormap. Default
True.pixel_spread_nodes – amount of pixel units in which to “spread” pixel values in the resulting rasterization before plotting. Default amount of spreading is 7 pixels. For more on spreading, see the datashader documentation.
reduction_nodes – the means of projecting from data space to pixel space for the rasterization of nodes. Default
Noneusesds.count(), essentially building a 2d histogram. For more on reductions indatashader, see the datashader documentation, and for a complete list of reduction functions available, see the datashader API docs.log_cmap_edges – whether to use a logarithmic (base 10) scale for the colormap. Default
True.pixel_spread_edges – amount of pixel units in which to “spread” pixel values in the resulting rasterization before plotting. Default amount of spreading is 1 pixel. For more on spreading, see the datashader documentation.
reduction_edges – the means of projecting from data space to pixel space for the rasterization of edges. Default
Noneusesds.count(), essentially building a 2d histogram. For more on reductions indatashader, see the datashader documentation, and for a complete list of reduction functions available, see the datashader API docs.fig – default
Nonebuilds new figure. If a figure is specified,Axisinstances will be drawn on that figure. Note:figandaxmust BOTH beNoneto instantiate new figure and axes.ax – default
Nonebuilds new axis. If an axis is specified,Axisinstances will be drawn on that axis. Note:figandaxmust BOTH beNoneto instantiate new figure and axes.figsize – size of figure. Note: only works if instantiating new figure and axes (e.g.
figandaxareNone).dpi – resolution (Dots Per Inch) of resulting figure. A higher-than-usual DPI is recommended to show more pixels in the final rasterization, which will show more nuance.
axes_off – whether to turn off Cartesian x, y axes in resulting
matplotlibfigure (defaultTruehides the x and y axes).buffer – fraction of the axes past which to buffer x and y dimensions (e.g. setting
bufferto 0.1 will find the maximum radius spanned by anyAxisinstance and set the x and y bounds as(-max_radius - buffer * max_radius, max_radius + buffer * max_radius)).show_axes_labels – whether to label the hive plot axes in the figure (uses
Axis.long_namefor eachAxis.)axes_labels_buffer – fraction which to radially buffer axes labels (e.g. setting
axes_label_bufferto 1.1 will be 10% further past the end of the axis moving from the origin of the plot).axes_labels_fontsize – font size for hive plot axes labels.
axes_kwargs – additional params that will be applied to all axes. Note, these are kwargs that affect a
plt.plot()call.text_kwargs – additional kwargs passed to
plt.text()call.fig_kwargs – additional values to be called in
plt.subplots()call. Note iffigsizeis added here, then it will be prioritized over thefigsizeparameter.edge_kwargs – additional params that will be applied to the final
plt.imshow()call on the edge rasterization. Must not clash with the cmap_edges, vmin_edges, or vmax_edges parameters.
- Raises:
ValueError – If a column-based
reduction_edges(e.g.ds.sum('col'),ds.mean('col'),ds.count_cat('col')) references an edge metadata column that does not exist for the selectedtag.- Returns:
matplotlibfigure, axis, the image corresponding to node data, and the image corresponding to edge data. If there are no edges / nodes to plot, the returned edges image / nodes image will beNone.
- hiveplotlib.viz.datashader.datashade_nodes_mpl(instance: BaseHivePlot | HivePlot | P2CP, cmap: str | ListedColormap = 'copper', vmin: float = 1, vmax: float | None = None, log_cmap: bool = True, pixel_spread: int = 7, reduction: Reduction | None = None, buffer: float = 0.1, fig: Figure | None = None, ax: Axes | None = None, figsize: Tuple[float, float] = (10, 10), dpi: int = 150, axes_off: bool = True, fig_kwargs: dict | None = None, **im_kwargs) Tuple[Figure, Axes, AxesImage | None]#
matplotlibvisualization of nodes / points in aHivePlot/P2CPinstance usingdatashader.The main idea of
datashaderis rather than plot all the points on top of each other in a figure, one can instead essentially build up a single 2d image of the points in 2-space. We can then plot just this rasterization, which is much smaller. By using the default reduction functionreduction=ds.count()(counting values in bins), we are essentially building a 2d histogram. For more on reductions indatashader, see the datashader documentation, and for a complete list of reduction functions available, see the datashader API docs.Note
A higher
dpivalue when datashading will allow for more nuance in the rasterization, but will require adjusting thepixel_spreadparameter accordingly (larger spread likely needed when using a higherdpi).Experimentation with different values for
pixel_spreadis encouraged. As the name suggests, this parameter spreads out calculated pixel values in the rasterization radially. Values that are too low tends to result in smaller, harder to see points in the final visualization. For more on spreading, see the datashader documentation.Any provided node plotting keyword arguments in
HivePlot.nodes.node_viz_kwargswill be disregarded in this visualization, as this flexibility is reserved for datashading the nodes. Inclusion of anynode_kwargshere will also raise a warning.- Parameters:
instance –
HivePlotorP2CPinstance for which we want to draw edges.cmap – which colormap to use for the datashaded nodes. Default “copper”.
vmin – minimum value used in the colormap for plotting the rasterization of curves. Default 1.
vmax – maximum value used in the colormap for plotting the rasterization of curves. Default
Nonefinds and uses the maximum bin value of the calculated rasterization.log_cmap – whether to use a logarithmic (base 10) scale for the colormap. Default
True.reduction – the means of projecting from data space to pixel space for the rasterization. Default
Noneusesds.count(), essentially building a 2d histogram. For more on reductions indatashader, see the datashader documentation, and for a complete list of reduction functions available, see the datashader API docs.pixel_spread – amount of pixel units in which to “spread” pixel values in the resulting rasterization before plotting. Default amount of spreading is 7 pixels. For more on spreading, see the datashader documentation.
buffer – fraction of the axes past which to buffer x and y dimensions (e.g. setting
bufferto 0.1 will find the maximum radius spanned by anyAxisinstance and set the x and y bounds as(-max_radius - buffer * max_radius, max_radius + buffer * max_radius)).fig – default
Nonebuilds new figure. If a figure is specified,Axisinstances will be drawn on that figure. Note:figandaxmust BOTH beNoneto instantiate new figure and axes.ax – default
Nonebuilds new axis. If an axis is specified,Axisinstances will be drawn on that axis. Note:figandaxmust BOTH beNoneto instantiate new figure and axes.figsize – size of figure. Note: only works if instantiating new figure and axes (e.g.
figandaxareNone).dpi – resolution (Dots Per Inch) of resulting figure. A higher-than-usual DPI is recommended to show more pixels in the final rasterization, which will show more nuance.
axes_off – whether to turn off Cartesian x, y axes in resulting
matplotlibfigure (defaultTruehides the x and y axes).fig_kwargs – additional values to be called in
plt.subplots()call. Note iffigsizeis added here, then it will be prioritized over thefigsizeparameter.im_kwargs – additional params that will be applied to the final
plt.imshow()call on the rasterization. Must not clash with the cmap, vmin, or vmax parameters.
- Returns:
matplotlibfigure, axis, image. If there are no nodes to plot, the returned image will beNone.
- hiveplotlib.viz.datashader.edge_viz(instance: BaseHivePlot | HivePlot | P2CP, tag: Hashable | None = None, cmap: str | ListedColormap | None = None, vmin: float = 1, vmax: float | None = None, log_cmap: bool = True, pixel_spread: int = 1, reduction: Reduction | None = None, buffer: float = 0.1, fig: Figure | None = None, ax: Axes | None = None, figsize: Tuple[float, float] = (10, 10), dpi: int = 150, axes_off: bool = True, fig_kwargs: dict | None = None, **im_kwargs) Tuple[Figure, Axes, AxesImage | None]#
matplotlibvisualization of constructed edges in aHivePlotorP2CPinstance usingdatashader.The main idea of
datashaderis rather than plot all the lines on top of each other in a figure, one can instead essentially build up a single 2d image of the lines in 2-space. We can then plot just this rasterization, which is much smaller. By using the default reduction functionreduction=ds.count(counting values in bins), we are essentially building a 2d histogram. For more on reductions indatashader, see the datashader documentation, and for a complete list of reduction functions available, see the datashader API docs.Note
A higher
dpivalue when datashading will allow for more nuance in the rasterization, but will require adjusting thepixel_spreadparameter accordingly (larger spread likely needed when using a higherdpi).Experimentation with different (low) values for
pixel_spreadis encouraged. As the name suggests, this parameter spreads out calculated pixel values in the rasterization radially. Values that are too low tends to result in the thinner, more isolated curves “breaking apart” in the final visualization. For more on spreading, see the datashader documentation.Any provided edge plotting keyword arguments in
HivePlot.edges.edge_viz_kwargswill be disregarded in this visualization, as this flexibility is reserved for datashading the edges. Inclusion of any edge kwargs here as part of theim_kwargswill likely trigger an error.- Parameters:
instance –
HivePlotorP2CPinstance for which we want to draw edges.tag – which tag of data to plot. If
Noneis provided, then plotting will occur if there is only one tag in the instance. For more on data tags, see further discussion in the Comparing Network Subgroups Notebook.cmap – which colormap to use for the datashaded edges. Default uses a
seaborncolormap similar to thematplotlib"Blues"colormap.vmin – minimum value used in the colormap for plotting the rasterization of curves. Default 1.
vmax – maximum value used in the colormap for plotting the rasterization of curves. Default
Nonefinds and uses the maximum bin value of the calculated rasterization.log_cmap – whether to use a logarithmic (base 10) scale for the colormap. Default
True.reduction – the means of projecting from data space to pixel space for the rasterization. Default
Noneusesds.count(), essentially building a 2d histogram. For more on reductions indatashader, see the datashader documentation, and for a complete list of reduction functions available, see the datashader API docs.pixel_spread – amount of pixel units in which to “spread” pixel values in the resulting rasterization before plotting. Default amount of spreading is 1 pixel. For more on spreading, see the datashader documentation.
buffer – fraction of the axes past which to buffer x and y dimensions (e.g. setting
bufferto 0.1 will find the maximum radius spanned by anyAxisinstance and set the x and y bounds as(-max_radius - buffer * max_radius, max_radius + buffer * max_radius)).fig – default
Nonebuilds new figure. If a figure is specified,Axisinstances will be drawn on that figure. Note:figandaxmust BOTH beNoneto instantiate new figure and axes.ax – default
Nonebuilds new axis. If an axis is specified,Axisinstances will be drawn on that axis. Note:figandaxmust BOTH beNoneto instantiate new figure and axes.figsize – size of figure. Note: only works if instantiating new figure and axes (e.g.
figandaxareNone).dpi – resolution (Dots Per Inch) of resulting figure. A higher-than-usual DPI is recommended to show more pixels in the final rasterization, which will show more nuance.
axes_off – whether to turn off Cartesian x, y axes in resulting
matplotlibfigure (defaultTruehides the x and y axes).fig_kwargs – additional values to be called in
plt.subplots()call. Note iffigsizeis added here, then it will be prioritized over thefigsizeparameter.im_kwargs – additional params that will be applied to the final
plt.imshow()call on the rasterization. Must not clash with the cmap, vmin, or vmax parameters.
- Raises:
ValueError – If a column-based
reduction(e.g.ds.sum('col'),ds.mean('col'),ds.count_cat('col')) references an edge metadata column that does not exist for the selectedtag.- Returns:
matplotlibfigure, axis, image. If there are no edges to plot, the returned image will beNone.
- hiveplotlib.viz.datashader.hive_plot_viz(instance: BaseHivePlot | HivePlot | P2CP, tag: Hashable | None = None, cmap_edges: str | ListedColormap | None = None, cmap_nodes: str | ListedColormap = 'copper', vmin_nodes: float = 1, vmax_nodes: float | None = None, vmin_edges: float = 1, vmax_edges: float | None = None, node_kwargs: dict | None = None, log_cmap_nodes: bool = True, pixel_spread_nodes: int = 7, reduction_nodes: Reduction | None = None, log_cmap_edges: bool = True, pixel_spread_edges: int = 1, reduction_edges: Reduction | None = None, fig: Figure | None = None, ax: Axes | None = None, figsize: Tuple[float, float] = (10, 10), dpi: int = 150, axes_off: bool = True, buffer: float = 0.1, show_axes_labels: bool = True, axes_labels_buffer: float = 1.1, axes_labels_fontsize: int = 16, axes_kwargs: dict | None = None, text_kwargs: dict | None = None, fig_kwargs: dict | None = None, **edge_kwargs) Tuple[Figure, Axes, AxesImage | None, AxesImage | None]#
matplotlibvisualization of aHivePlotorP2CPinstance usingdatashader.Plots both nodes and edges with datashader along with standard hive plot / P2CP axes.
The main idea of
datashaderis rather than plot all the lines on top of each other in a figure, one can instead essentially build up a single 2d image of the lines in 2-space. We can then plot just this rasterization, which is much smaller. By using the default reduction functionds.count()(counting values in bins), we are essentially building a 2d histogram. For more on reductions indatashader, see the datashader documentation, and for a complete list of reduction functions available, see the datashader API docs.Note
A higher
dpivalue when datashading will allow for more nuance in the rasterization, but will require adjusting thepixel_spread_nodesandpixel_spread_edgesparameters accordingly (larger spreads likely needed when using a higherdpi). Higherdpivalues will also increase computation time.Experimentation with different (low) values for
pixel_spread_nodesandpixel_spread_edgesis encouraged. As the name suggests, this parameter spreads out calculated pixel values in the rasterization radially. Values that are too low tends to result in the thinner, more isolated curves “breaking apart” in the final visualization. For more on spreading, see the datashader documentation.Any provided node plotting keyword arguments in
HivePlot.nodes.node_viz_kwargswill be disregarded in this visualization, as this flexibility is reserved for datashading the nodes. Inclusion of anynode_kwargshere will also raise a warning.Any provided edge plotting keyword arguments in
HivePlot.edges.edge_viz_kwargswill be disregarded in this visualization, as this flexibility is reserved for datashading the edges. Inclusion of any edge kwargs here as part of theim_kwargswill likely trigger an error.- Parameters:
instance –
HivePlotorP2CPinstance for which we want to visualize.tag – which tag of data to plot. If
Noneis provided, then plotting will occur if there is only one tag in the instance. For more on data tags, see further discussion in the Comparing Network Subgroups Notebook.cmap_edges – which colormap to use for the datashaded edges. Default uses a
seaborncolormap similar to thematplotlib"Blues"colormap.cmap_nodes – which colormap to use for the datashaded nodes. Default “copper”.
vmin_nodes – minimum value used in the colormap for plotting the rasterization of nodes. Default 1.
vmax_nodes – maximum value used in the colormap for plotting the rasterization of nodes. Default
Nonefinds and uses the maximum bin value of the calculated rasterization.vmin_edges – minimum value used in the colormap for plotting the rasterization of edges. Default 1.
vmax_edges – maximum value used in the colormap for plotting the rasterization of edges. Default
Nonefinds and uses the maximum bin value of the calculated rasterization.node_kwargs – additional params that will be applied to the final
plt.imshow()call on the edge rasterization. Must not clash with the cmap_nodes, vmin_nodes, or vmax_nodes parameters.log_cmap_nodes – whether to use a logarithmic (base 10) scale for the colormap. Default
True.pixel_spread_nodes – amount of pixel units in which to “spread” pixel values in the resulting rasterization before plotting. Default amount of spreading is 7 pixels. For more on spreading, see the datashader documentation.
reduction_nodes – the means of projecting from data space to pixel space for the rasterization of nodes. Default
Noneusesds.count(), essentially building a 2d histogram. For more on reductions indatashader, see the datashader documentation, and for a complete list of reduction functions available, see the datashader API docs.log_cmap_edges – whether to use a logarithmic (base 10) scale for the colormap. Default
True.pixel_spread_edges – amount of pixel units in which to “spread” pixel values in the resulting rasterization before plotting. Default amount of spreading is 1 pixel. For more on spreading, see the datashader documentation.
reduction_edges – the means of projecting from data space to pixel space for the rasterization of edges. Default
Noneusesds.count(), essentially building a 2d histogram. For more on reductions indatashader, see the datashader documentation, and for a complete list of reduction functions available, see the datashader API docs.fig – default
Nonebuilds new figure. If a figure is specified,Axisinstances will be drawn on that figure. Note:figandaxmust BOTH beNoneto instantiate new figure and axes.ax – default
Nonebuilds new axis. If an axis is specified,Axisinstances will be drawn on that axis. Note:figandaxmust BOTH beNoneto instantiate new figure and axes.figsize – size of figure. Note: only works if instantiating new figure and axes (e.g.
figandaxareNone).dpi – resolution (Dots Per Inch) of resulting figure. A higher-than-usual DPI is recommended to show more pixels in the final rasterization, which will show more nuance.
axes_off – whether to turn off Cartesian x, y axes in resulting
matplotlibfigure (defaultTruehides the x and y axes).buffer – fraction of the axes past which to buffer x and y dimensions (e.g. setting
bufferto 0.1 will find the maximum radius spanned by anyAxisinstance and set the x and y bounds as(-max_radius - buffer * max_radius, max_radius + buffer * max_radius)).show_axes_labels – whether to label the hive plot axes in the figure (uses
Axis.long_namefor eachAxis.)axes_labels_buffer – fraction which to radially buffer axes labels (e.g. setting
axes_label_bufferto 1.1 will be 10% further past the end of the axis moving from the origin of the plot).axes_labels_fontsize – font size for hive plot axes labels.
axes_kwargs – additional params that will be applied to all axes. Note, these are kwargs that affect a
plt.plot()call.text_kwargs – additional kwargs passed to
plt.text()call.fig_kwargs – additional values to be called in
plt.subplots()call. Note iffigsizeis added here, then it will be prioritized over thefigsizeparameter.edge_kwargs – additional params that will be applied to the final
plt.imshow()call on the edge rasterization. Must not clash with the cmap_edges, vmin_edges, or vmax_edges parameters.
- Raises:
ValueError – If a column-based
reduction_edges(e.g.ds.sum('col'),ds.mean('col'),ds.count_cat('col')) references an edge metadata column that does not exist for the selectedtag.- Returns:
matplotlibfigure, axis, the image corresponding to node data, and the image corresponding to edge data. If there are no edges / nodes to plot, the returned edges image / nodes image will beNone.
- hiveplotlib.viz.datashader.node_viz(instance: BaseHivePlot | HivePlot | P2CP, cmap: str | ListedColormap = 'copper', vmin: float = 1, vmax: float | None = None, log_cmap: bool = True, pixel_spread: int = 7, reduction: Reduction | None = None, buffer: float = 0.1, fig: Figure | None = None, ax: Axes | None = None, figsize: Tuple[float, float] = (10, 10), dpi: int = 150, axes_off: bool = True, fig_kwargs: dict | None = None, **im_kwargs) Tuple[Figure, Axes, AxesImage | None]#
matplotlibvisualization of nodes / points in aHivePlot/P2CPinstance usingdatashader.The main idea of
datashaderis rather than plot all the points on top of each other in a figure, one can instead essentially build up a single 2d image of the points in 2-space. We can then plot just this rasterization, which is much smaller. By using the default reduction functionreduction=ds.count()(counting values in bins), we are essentially building a 2d histogram. For more on reductions indatashader, see the datashader documentation, and for a complete list of reduction functions available, see the datashader API docs.Note
A higher
dpivalue when datashading will allow for more nuance in the rasterization, but will require adjusting thepixel_spreadparameter accordingly (larger spread likely needed when using a higherdpi).Experimentation with different values for
pixel_spreadis encouraged. As the name suggests, this parameter spreads out calculated pixel values in the rasterization radially. Values that are too low tends to result in smaller, harder to see points in the final visualization. For more on spreading, see the datashader documentation.Any provided node plotting keyword arguments in
HivePlot.nodes.node_viz_kwargswill be disregarded in this visualization, as this flexibility is reserved for datashading the nodes. Inclusion of anynode_kwargshere will also raise a warning.- Parameters:
instance –
HivePlotorP2CPinstance for which we want to draw edges.cmap – which colormap to use for the datashaded nodes. Default “copper”.
vmin – minimum value used in the colormap for plotting the rasterization of curves. Default 1.
vmax – maximum value used in the colormap for plotting the rasterization of curves. Default
Nonefinds and uses the maximum bin value of the calculated rasterization.log_cmap – whether to use a logarithmic (base 10) scale for the colormap. Default
True.reduction – the means of projecting from data space to pixel space for the rasterization. Default
Noneusesds.count(), essentially building a 2d histogram. For more on reductions indatashader, see the datashader documentation, and for a complete list of reduction functions available, see the datashader API docs.pixel_spread –
amount of pixel units in which to “spread” pixel values in the resulting rasterization before plotting. Default amount of spreading is 7 pixels. For more on spreading, see the datashader documentation.
buffer – fraction of the axes past which to buffer x and y dimensions (e.g. setting
bufferto 0.1 will find the maximum radius spanned by anyAxisinstance and set the x and y bounds as(-max_radius - buffer * max_radius, max_radius + buffer * max_radius)).fig – default
Nonebuilds new figure. If a figure is specified,Axisinstances will be drawn on that figure. Note:figandaxmust BOTH beNoneto instantiate new figure and axes.ax – default
Nonebuilds new axis. If an axis is specified,Axisinstances will be drawn on that axis. Note:figandaxmust BOTH beNoneto instantiate new figure and axes.figsize – size of figure. Note: only works if instantiating new figure and axes (e.g.
figandaxareNone).dpi – resolution (Dots Per Inch) of resulting figure. A higher-than-usual DPI is recommended to show more pixels in the final rasterization, which will show more nuance.
axes_off – whether to turn off Cartesian x, y axes in resulting
matplotlibfigure (defaultTruehides the x and y axes).fig_kwargs – additional values to be called in
plt.subplots()call. Note iffigsizeis added here, then it will be prioritized over thefigsizeparameter.im_kwargs – additional params that will be applied to the final
plt.imshow()call on the rasterization. Must not clash with the cmap, vmin, or vmax parameters.
- Returns:
matplotlibfigure, axis, image. If there are no nodes to plot, the returned image will beNone.