Highlight the most connected people in a sample social network

import matplotlib.pyplot as plt import numpy as np names = ['Carl Vrba', 'Dong Pea', 'Arnetta Body', 'Valentin Hone', 'Phung Pleiman', 'Trenton Stuckey', 'Matt Crooker', 'Tawanna Leick', 'Elsie Twombly', 'Penelope Sneed', 'Oren Jasso', 'Madelene Baillargeon', 'Bronwyn Paz', 'Jeremy Didion', 'Sheree Mazur', 'Tawna Keeling', 'Melany Lohman', 'Clyde Ashline', 'Hassan Renzi', 'Isadora Upham', 'Shae Viloria', 'Toi Cobler', 'Adelle Hickel', 'Lindsay Vidales', 'Ester Paulus', 'Tarra Singh', 'An Hook', 'Dorothy Halberg', 'Maragret Toledo', 'Zana Dubiel', 'Josiah Margolin', 'Darline Mitzel', 'Renate Roker', 'Johnie Capuano', 'Chas Champ', 'Dayle Browning', 'Melvina Herd', 'Marcellus Avis', 'Evon Mariano', 'So Yarberry', 'Evangelina Marchan', 'Lyda Trollinger', 'Kristine Mckissack', 'Kurtis Propes', 'Sharice Heitmann', 'Saran Plude', 'Leilani Marshburn', 'Alla Boggs', 'Nedra Zimmerer', 'Gia Dansby', 'Antonia Seamon', 'Cathryn Rocha', 'Sharyl Rudder', 'Janyce Maza', 'Samual Costigan', 'Emmett Clymer', 'Kirstin Drury', 'Shandi Mullenax', 'Gordon Chabot', 'Hang Mineo', 'Milo Gambrell', 'Cleopatra Tharrington', 'Jenice Loe', 'Shanelle Welter', 'Sheba Bien', 'Bob Alberts', 'Lorrie Freeland', 'Windy Reisner', 'Johnny Lyall', 'Rodolfo Swinger', 'Cathern Batt', 'Bethanie Strouth', 'Eliseo Drey', 'Letisha Alley', 'Jeri Bator', 'Wayne Mcduffy', 'Kathlyn Ching', 'Lanelle Sickler', 'Lavon Mansour', 'Thu Greig', 'Anthony Casali', 'Elly Schuelke', 'Rebbecca Hightower', 'Alexandria Aiello', 'Julieann Pardee', 'Diego Chambless', 'Cleveland Brashears', 'Sherron Bain', 'Mellissa Radley', 'Sara Mongold', 'Casandra Gourley', 'Darnell Reinhard', 'Roselle Brothers', 'Jacquelyne Wolfenbarger', 'Robbie Porcaro', 'Lavonda Pichon', 'Hank Delancey', 'Louise Cottle', 'Rosario Alphonse', 'Pasty Stinson', 'Nicolasa Beekman', 'Willia Martelli', 'Shala Naquin', 'Rick Hyun', 'Christina Wirtz', 'Joey Castruita', 'Glady Wheeless', 'Hermila Moronta', 'Rosette Patnaude', 'Foster Mcbath', 'Marquita Seabaugh', 'Latanya Rough', 'May Hennings', 'Susan Heitman', 'Kristen Mumaw', 'Lorita Dunkley', 'Patsy Gist', 'Sharon Gosnell', 'Luz Barth', 'Burton Shearin', 'Ferdinand Fuerst', 'Isaac Delucia', 'Lin Bianchi', 'Racquel Tewell', 'Soon Edman', 'Dreama Beasley', 'Judy Pumphrey', 'Teresa Bothwell', 'Kenneth Mendonca', 'Shara Schwager', 'Brad Singh', 'Stefanie Whittingham', 'Alica Barrera', 'Theodore Ketter', 'Vanita Rison', 'Karyn Tarrance', 'Mistie Hao', 'Dimple Fesler', 'Mana Cordle', 'Gaylene Dooley', 'Carey Unsworth', 'Carolynn Gardiner', 'Charissa Edgerly', 'Florene Hills', 'Stephen Seddon', 'Latricia Oakes', 'Sana Gammons', 'Gudrun Vaca', 'Jeanne Bomar', 'Gwenda Hildebrand', 'Florence Antes', 'Jimmy Monsour', 'Jasmin Waybright', 'Alayna Casteel', 'Fairy Messineo', 'Lashon Losh', 'Waneta Bradfield', 'Kazuko Thomsen', 'Tobi Epley', 'Yetta Sproul', 'Isa Sevy', 'Rosio Colley', 'Rena Hinshaw', 'Ressie Rosemond', 'Jeffry Seedorf', 'Lorri Buskirk', 'Earlie Berning', 'Angelic Buhr', 'Cathie Keehn', 'Dixie Flegle', 'Genevive Kirwan', 'Sebastian Hempel', 'Penny Towell', 'Jesse Kinder', 'Collene Andreasen', 'Elvera Jakubowski', 'Winifred Such', 'Fonda Hornung', 'Darius Underwood', 'Walter Brymer', 'Phylis Brinks', 'Willie Lotz', 'Mae Smedley', 'Tory Marques', 'Myesha Cuenca', 'Khadijah Engel', 'Oswaldo Keefer', 'Quinton Bohan', 'Rosana Hammill', 'Missy Christner', 'Fernande Alvarez', 'Esteban Carroll', 'Cortney Obando', 'Kristopher Shewmake', 'Kristian Burpee', 'Royal Kraatz', 'Shella Kleinman', 'Bonnie Arnold', 'Jeane Villa', 'Shin Sojka', 'Russel Statler', 'Hattie Tiggs', 'Millard Borton', 'Lynne Erhart', 'Coralee Learned', 'Cecila Yahn', 'Joseph Narvaez', 'Marlyn Gunnerson', 'Shera Waldrup', 'Dollie Byrom', 'Lita Rouse', 'Marisela Slaten', 'Prudence Crisler', 'Andrew Schimmel', 'Irmgard Gabourel', 'Yoshie Pigg', 'Maya Thorpe', 'Mickey Cornish', 'Gertrudis Nesbitt', 'Chere Raley', 'Rosanne Trevizo', 'Tien Paradis', 'Leopoldo Mayhugh', 'Tuyet Forgione', 'Helga Goodell', 'Magaret Seaborn', 'Madeleine Fedele', 'Trisha Reza', 'Ahmad Ivers', 'Rebeca Duhaime', 'Evelia Sadowski', 'Maren Lasley', 'Raleigh Mirsky', 'Ginger Mccallum', 'Marlen Vieira', 'My Daddario', 'Carolyn Brownlow', 'Gema Standard', 'Lorrine Symes', 'Ella Maza', 'Jannie Okelly', 'Kermit Rohrbaugh', 'Maryln Nachman', 'Jo Fazekas', 'Ivy Brumer', 'Timmy Wacaster', 'Dianne Puskar', 'Carole Redrick', 'Vincent Carmouche', 'Rosalie Shoener'] inches = 10 radius = 10 max_friends = 30 width, height = inches*100, inches*100 center_x, center_y = width/2, height/2 concentric_circles_radius_step = (min([width, height]) / 2) / max_friends all_names = len(names) show_most_connected = 10 most_connected_angle_step = 360 / show_most_connected most_connected_angle = 0 unique_friend_lens = set() name_friends = {} fig, ax = plt.subplots(figsize=(inches, inches)) for name in names: friends = np.random.randint(0, max_friends) friends_indices = np.random.randint(0, len(names)-1, friends) friends_names = [names[fidx] for fidx in friends_indices] name_friends[name] = friends_names # Place a person with max_friends on innermost circle, and move to the periphery from there for idx, (name, friends) in enumerate(sorted(name_friends.items(), key=lambda x: len(x[1]), reverse=True)): friends_count = len(friends) radius = (max_friends - friends_count + 1) * concentric_circles_radius_step angle_rad = np.radians(np.random.randint(0, 360)) x = center_x + radius * np.sin(angle_rad) y = center_y + radius * np.cos(angle_rad) color, point_size = 'grey', 4 if idx < show_most_connected: most_connected_angle_rad = np.radians(most_connected_angle) mcr = (max_friends + 2) * concentric_circles_radius_step mcx = center_x + mcr * np.sin(most_connected_angle) mcy = center_y + mcr * np.cos(most_connected_angle) plt.annotate(name, xy=(x, y), xytext=(mcx, mcy), ha='center', fontsize=8, arrowprops=dict(facecolor='grey', arrowstyle='->', lw=0.5)) most_connected_angle += most_connected_angle_step color, point_size = 'red', 8 plt.plot(x, y, '.', markersize=point_size, color=color) for friend in friends: friends_names = name_friends[friend] friends_count1 = len(friends_names) angle_rad1 = np.radians(np.random.randint(0, 360)) radius1 = (max_friends - friends_count1 + 1) * concentric_circles_radius_step x1 = center_x + radius1 * np.sin(angle_rad1) y1 = center_y + radius1 * np.cos(angle_rad1) plt.plot([x, x1], [y, y1], '-', lw=0.1, color='grey', alpha=0.5) plt.axis('off') plt.tight_layout() plt.show() Visualization highlighting the most connected people in a fictive social network