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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add hatches to nodes #97

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions netgraph/_graph_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
_make_pretty,
_rank,
_normalize_numeric_argument,
_normalize_string_argument,
_normalize_color_argument,
_normalize_shape_argument,
_rescale_dict_values,
Expand Down Expand Up @@ -113,6 +114,12 @@ class BaseGraph(object):
If the type is dict, maps each node to an individual size.

.. note:: Values are rescaled by :py:const:`BASE_SCALE` (0.01) to be compatible with layout routines in igraph and networkx.
node_hatch : str or dict, default ""
Node hatch pattern.
If the type is str, all nodes have the same hatch pattern.
If the type is dict, maps each node to an individual hatch pattern.

Refer to https://matplotlib.org/stable/gallery/shapes_and_collections/hatch_style_reference.html for available hatch patterns.

node_edge_width : float or dict, default 0.5
Line width of node marker border.
Expand Down Expand Up @@ -262,6 +269,7 @@ def __init__(self, edges,
node_layout_kwargs=None,
node_shape='o',
node_size=3.,
node_hatch="",
node_edge_width=0.5,
node_color='w',
node_edge_color=DEFAULT_COLOR,
Expand Down Expand Up @@ -298,6 +306,7 @@ def __init__(self, edges,
# Convert all node and edge parameters to dictionaries.
node_shape = _normalize_shape_argument(node_shape, self.nodes, 'node_shape')
node_size = _normalize_numeric_argument(node_size, self.nodes, 'node_size')
node_hatch = _normalize_string_argument(node_hatch, self.nodes, 'node_hatch')
node_edge_width = _normalize_numeric_argument(node_edge_width, self.nodes, 'node_edge_width')
node_color = _normalize_color_argument(node_color, self.nodes, 'node_color')
node_edge_color = _normalize_color_argument(node_edge_color, self.nodes, 'node_edge_color')
Expand All @@ -323,7 +332,7 @@ def __init__(self, edges,
node_layout, node_layout_kwargs)
self.node_artists = dict()
self.draw_nodes(self.nodes, self.node_positions,
node_shape, self.node_size, node_edge_width,
node_shape, self.node_size, node_hatch, node_edge_width,
node_color, node_edge_color, node_alpha, node_zorder)

self.edge_layout = self._initialize_edge_layout(edge_layout, edge_layout_kwargs)
Expand Down Expand Up @@ -519,7 +528,7 @@ def _initialize_axis(self, ax):
raise TypeError(f"Variable 'ax' either None or a matplotlib axis instance. However, type(ax) is {type(ax)}.")


def draw_nodes(self, nodes, node_positions, node_shape, node_size,
def draw_nodes(self, nodes, node_positions, node_shape, node_size, node_hatch,
node_edge_width, node_color, node_edge_color, node_alpha,
node_zorder):
"""Draw or update node artists.
Expand All @@ -535,6 +544,8 @@ def draw_nodes(self, nodes, node_positions, node_shape, node_size,
Specification is as for matplotlib.scatter marker, i.e. one of 'so^>v<dph8'.
node_size : dict
Mapping of nodes to sizes.
node_hatch : dict
Mapping of nodes to hatch patterns.
node_edge_width : dict
Mapping of nodes to marker edge widths.
node_color : dict
Expand All @@ -558,6 +569,7 @@ def draw_nodes(self, nodes, node_positions, node_shape, node_size,
kwargs = dict(
xy = node_positions[node],
size = node_size[node],
hatch = node_hatch[node],
facecolor = node_color[node],
edgecolor = node_edge_color[node],
linewidth = node_edge_width[node],
Expand Down