Skip to content

Instantly share code, notes, and snippets.

@dvnoble
Created April 19, 2023 01:00
Show Gist options
  • Save dvnoble/cbaf206238eab571f57e84657ff11041 to your computer and use it in GitHub Desktop.
Save dvnoble/cbaf206238eab571f57e84657ff11041 to your computer and use it in GitHub Desktop.
My background generator for Linkedin background picture.
import networkx as nx
import matplotlib.pyplot as plt
# Generate a random graph with 6 communities
size1= 150
size2= 150
G = nx.stochastic_block_model([size1, size2], [[0.03,0.001],[0.001,0.02]])
node_colors = [ '#01f2ab'] * size1 + ['#f20148'] * size2
node_outline= [ '#01a675'] * size1 + ['#a60131'] * size2
edge_colors = []
for (u, v) in G.edges():
if node_colors[u] == node_colors[v]:
# If the endpoints have the same color, set edge color to their color
edge_colors.append(node_colors[u])
else:
# If the endpoints have different colors, set edge color to grey
edge_colors.append('#cccccc')
nx.draw_kamada_kawai(G, node_size=30, node_color=node_colors, edge_color=edge_colors, edgecolors=node_outline, width=0.2, linewidths=0.2)
fig = plt.gcf()
fig.set_facecolor('#1d2226')
plt.savefig('networkx_graph.png', dpi=300,facecolor=fig.get_facecolor())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment