.. _sphx_glr_gallery_plot_degrees.py: Coloring the degrees of a node ------------------------------- Test .. image:: /gallery/images/sphx_glr_plot_degrees_001.png :align: center .. code-block:: python import networkx as nx import matplotlib.pyplot as plt import random from grave import plot_network graph = nx.barbell_graph(10, 14) nx.set_node_attributes(graph, dict(graph.degree()), 'degree') def degree_colorer(node_attributes): deg = node_attributes['degree'] shape = random.choice(['s', 'o', '^', 'v', '8']) if deg > 5: return {'color': 'r', 'size': 20*deg, 'shape': shape} return {'color': 'b', 'size': 20*deg, 'shape': shape} def pathological_edge_style(edge_attrs): return {'color': random.choice(['r', (0, 1, 0, .5), 'xkcd:ocean'])} fig, ax = plt.subplots() plot_network(graph, ax=ax, node_style=degree_colorer, edge_style=pathological_edge_style) plt.show() **Total running time of the script:** ( 0 minutes 0.050 seconds) .. only :: html .. container:: sphx-glr-footer .. container:: sphx-glr-download :download:`Download Python source code: plot_degrees.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_degrees.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_