Skip to content

Commit

Permalink
Vertex label color in mpl
Browse files Browse the repository at this point in the history
  • Loading branch information
iosonofabio committed Sep 26, 2023
1 parent 4852839 commit 9d72d1e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/igraph/drawing/matplotlib/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ def _draw_vertex_labels(self):
vertex.label_size,
)

label_color = kwds.get(
"vertex_label_color",
vertex.label_color,
)

# Locate text relative to vertex in data units. This is consistent
# with the vertex size being in data units, but might be not fully
# satisfactory when zooming in/out. In that case, revisit this
Expand All @@ -337,6 +342,7 @@ def _draw_vertex_labels(self):
xytext=xytext,
textcoords="offset points",
fontsize=label_size,
color=label_color,
ha="center",
va="center",
clip_on=True,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions tests/drawing/matplotlib/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ def test_basic(self):
fig, ax = plt.subplots()
plot(g, target=ax, layout=self.layout_small_ring)

@image_comparison(baseline_images=["graph_labels"], remove_text=True)
def test_labels(self):
plt.close("all")
g = Graph.Ring(5)
fig, ax = plt.subplots(figsize=(3, 3))
plot(
g, target=ax, layout=self.layout_small_ring,
vertex_label=['1', '2', '3', '4', '5'],
vertex_label_color='white',
vertex_label_size=16,
)

@image_comparison(baseline_images=["graph_layout_attribute"], remove_text=True)
def test_layout_attribute(self):
plt.close("all")
Expand Down

0 comments on commit 9d72d1e

Please sign in to comment.