A Pachinko figure relationship diagram in Python

Novels Pachinkoyou might want to see the complex relationships of the characters at a glance. The relationships between characters across generations make novels more interesting, but they can also be complex and difficult to understand. Python makes it easy to visualize and understand these pachinko table relationships.

In this article, we'll use the Pachinko Character Relationships in Pythonstep-by-step, breaking down the key pieces of code one by one. At the end of the post, you'll find the entire code in one place, so be sure to read it all the way through!

파친코 인물 관계도 포스트 그림

Overview of the Pachinko Novel

Novels Pachinkois an epic novel about four generations of an immigrant family set in Korea and Japan from the Japanese colonial period through the 1980s. The complex relationships between the main characters and the conflicts of the time period are interwoven, and understanding the connections between them is crucial to appreciating the novel. (If you have time, check out the Apple Original Pachinko).

Key character descriptions

  • Hunyi: The father of the Zen master, representing the first generation of the family.
  • Yang Jin: Sun-ja's mother and Hoon-i's wife, she is a devoted mother figure.
  • ZenThe protagonist of the novel, who sacrifices for his family in the face of hardship.
  • Hansu Ko: A successful Japanese businessman who is Zen's first love and a major source of conflict in the novel.
  • BackisakHe's a pastor, the husband of a priest, and they're building a new life together.
  • Number of HatsThe son of Sunja and Baek Isaac, he represents the third generation of his family to run the pachinko business in Japan.
  • NoahThe son of Seonja and Ko Hansoo, he struggles with his own identity.
  • Solomon: The son of a matriarch, he represents the fourth generation and lives a complicated life between Japan and the United States.
  • Etsuko: A Japanese woman who is the lover of Mozu and has a complicated family history.
  • one: Etsuko's daughter, who becomes romantically involved with Solomon.
  • Yumi: Solomon's lover, whose relationship with Solomon further complicates the story.
  • Kyunghee: The wife of Jacob, the brother of Jacob, another important figure in the family.
  • Changsoo KimA loyal subordinate of Hansoo Goh, who is his main helper.

Now let's visually depict the relationship between these characters in Python.

A Pachinko figure relationship diagram in Python

1. install the required packages and set the Korean font

First, you'll need to install the necessary packages and set the Korean font so that it doesn't break in the relationship diagram.

import networkx as nx
import matplotlib.pyplot as plt
from adjustText import adjust_text
import matplotlib.font_manager as fm

Set the # Korean font
font_path = 'C:/Windows/Fonts/NanumGothic.ttf' # need to check the actual font path
fontprop = fm.FontProperties(fname=font_path, size=12)

plt.rc('font', family=fontprop.get_name())

matplotlib library is used to visualize graphs, adjustTextis a package to prevent overlapping text. The font path should be set to the actual installed font path, in this case NanumGothic.

2. define people relationships and set up nodes

Define the relationships between the main characters in Pachinko to establish the nodes (people) and edges (relationship lines) of the graph.

Create a # Graph
G = nx.Graph()

Define # character relationships (set up relationships between characters)
characters = [
    ("Hoon Yi", "Zen Master", "Father and Daughter"),
    ("Yang Jin", "Zen Master", "Mother and Daughter"),
    ("Baek Isaac", "Mother", "Father"),
    ("Hansu Ko", "Noah", "Father"),
    ("Hansu", "Zen Master", "Lover"),
    ("Zen Master", "Hat", "Hat"),
    ("hat", "noah", "brother"),
    ("hat", "Solomon", "rich"),
    ("Solomon", "Yumi", "lover"),
    ("Etsuko", "Mother", "Lover"),
    ("Etsuko", "Hana", "mother and daughter"),
    ("Noah", "Akiko", "lover"),
    ("Solomon", "one", "lover"),
    ("BaekJoseph", "KyungHee", "couple"),
    ("Baek Joseph", "Baek Isaac", "brother"),
    ("Ko, Hansoo", "Kim, Changsoo", "Joo, Jong")
]

# Add characters and relation lines
for character1, character2, relation in characters:
    G.add_edge(character1, character2, relation=relation)

This code is called networkx library to connect relationships between people as nodes and edges. For example, ("Hunyi", "Zen Master", "Father and Daughter")indicates a father-daughter relationship between Hoon and Sun Tzu.

3. Set Generation-specific colors and layout

Now separate the characters into generations, and color them according to their generation.

# Generation Information Definition
generation_dict = {
    "Hunyi": "1st generation",
    "Yangjin": "1st generation",
    "Sunjah": "2nd generation",
    "Baek Isaac": "2nd generation",
    "Mother": "3rd generation",
    "Noah": "3rd generation",
    "Gohansoo": "2nd generation",
    "Solomon": "4th generation",
    "Yumi": "3rd generation",
    "Etsuko": "3rd generation",
    "Hana": "4th generation",
    "Akiko": "3rd generation",
    "White Joseph": "2nd generation",
    "Kyung-hee": "2nd generation",
    "Kim, Chang-Su": "Other"
}

Set colors based on # generation
color_map = {
    "1st generation": "lightblue",
    "2nd generation": "lightgreen",
    "3rd generation": "lightcoral",
    "4th generation": "lightpink",
    "other": "gray"
}

# Assign a generation-specific color to each node
node_colors = [color_map[generation_dict[node]] for node in G.nodes()]

Set up a # layout (balanced using spring_layout)
pos = nx.spring_layout(G)

The code above colors each person by their generation. For example, the first generation is colored lightblueand second generation is lightgreenfor the first time. spring_layouthelps ensure that nodes are balanced.

4. Draw a person relationship diagram

Now we'll actually draw the graph, adding nodes and edges (relationship lines) and relationship descriptions.

Graph #
plt.figure(figsize=(12, 8))

Draw the # nodes
nx.draw_networkx_nodes(G, pos, node_color=node_colors, node_size=2000, edgecolors='black', linewidths=2)

Draw the # relationship lines
nx.draw_networkx_edges(G, pos)

Add relationship descriptions on top of the # relationship line
edge_labels = nx.get_edge_attributes(G, 'relation')
nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_family=fontprop.get_name(), font_size=12)

Display the person's name on the # node
nx.draw_networkx_labels(G, pos, font_size=12, font_weight='bold', font_family=fontprop.get_name())

# Add a title
plt.title("Pachinko Major Characters Relationship Chart", size=20, fontweight='bold')

# Add a legend
import matplotlib.lines as mlines
legend_elements = [mlines.Line2D([], [], color=color, marker='o', linestyle='', markersize=10, label=gen)
                   for gen, color in color_map.items()]
plt.legend(handles=legend_elements, title="Generation", loc="lower center", bbox_to_anchor=(0.5, -0.05), ncol=5, fontsize=12, title_fontsize=12)

Output the # graph
plt.axis('off')
plt.tight_layout()
plt.show()

The code above displays each person's generational color, name, and relationship description in a graph. draw_networkx_nodes, draw_networkx_edges, draw_networkx_labelsto add the node, relationship line, and person name, respectively, and above the relationship line, the draw_networkx_edge_labelsin the relationship description.

Full code

import networkx as nx
import matplotlib.pyplot as plt
from adjustText import adjust_text
import matplotlib.font_manager as fm

Set the # Korean font
font_path = 'C:/Windows/Fonts/NanumGothic.ttf'
fontprop = fm.FontProperties(fname=font_path, size=12)

plt.rc('font', family=fontprop.get_name())

Create the # graph
G = nx.Graph()

Define # character relationships
characters = [
    ("Hoon Yi", "Zen Master", "Father and Daughter"),
    ("Yang Jin", "Zen Master", "Mother and Daughter"),
    ("Baek Isaac", "Mother", "Father", "Boo"), ("Baek

자"),
    ("Hansu Ko", "Noah", "Rich"),
    ("Hansu", "Zen master", "lover"),
    ("Zen master", "hat", "hat"),
    ("hat", "noah", "brother"),
    ("hat", "Solomon", "rich"),
    ("Solomon", "Yumi", "lover"),
    ("Etsuko", "Mother", "Lover"),
    ("Etsuko", "Hana", "mother and daughter"),
    ("Noah", "Akiko", "lover"),
    ("Solomon", "one", "lover"),
    ("BaekJoseph", "KyungHee", "couple"),
    ("Baek Joseph", "Baek Isaac", "brother"),
    ("Ko, Hansu", "Kim, Changsoo", "Jujong")
]

# Add characters and relation lines
for character1, character2, relation in characters:
    G.add_edge(character1, character2, relation=relation)

Define # generation information
generation_dict = {
    "Hunyi": "1st generation",
    "Yangjin": "1st generation",
    "Sunjah": "2nd generation",
    "Baek Isaac": "2nd generation",
    "Mother": "3rd generation",
    "Noah": "3rd generation",
    "Gohansoo": "2nd generation",
    "Solomon": "4th generation",
    "Yumi": "3rd generation",
    "Etsuko": "3rd generation",
    "Hana": "4th generation",
    "Akiko": "3rd generation",
    "White Joseph": "2nd generation",
    "Kyung-hee": "2nd generation",
    "Kim, Chang-Su": "Other"
}

Set colors based on # generation
color_map = {
    "1st generation": "lightblue",
    "2nd generation": "lightgreen",
    "3rd generation": "lightcoral",
    "4th generation": "lightpink",
    "other": "gray"
}

# Assign a generation-specific color to each node
node_colors = [color_map[generation_dict[node]] for node in G.nodes()]

Set up the # layout
pos = nx.spring_layout(G)

Draw the # graph
plt.figure(figsize=(12, 8))

Draw the # nodes
nx.draw_networkx_nodes(G, pos, node_color=node_colors, node_size=2000, edgecolors='black', linewidths=2)

Draw the # relationship lines
nx.draw_networkx_edges(G, pos)

Add relationship descriptions on top of the # relationship line
edge_labels = nx.get_edge_attributes(G, 'relation')
nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_family=fontprop.get_name(), font_size=12)

Display the person's name on the # node
nx.draw_networkx_labels(G, pos, font_size=12, font_weight='bold', font_family=fontprop.get_name())

# Add a title
plt.title("Pachinko Major Characters Relationship Chart", size=20, fontweight='bold')

# Add a legend
import matplotlib.lines as mlines
legend_elements = [mlines.Line2D([], [], color=color, marker='o', linestyle='', markersize=10, label=gen)
                   for gen, color in color_map.items()]
plt.legend(handles=legend_elements, title="Generation", loc="lower center", bbox_to_anchor=(0.5, -0.05), ncol=5, fontsize=12, title_fontsize=12)

Output the # graph
plt.axis('off')
plt.tight_layout()
plt.show()

Finalize

In this article, we learned how to visualize the Pachinko character relationships using Python. Graphing the complex relationships between characters makes it easier to understand the flow of the novel. Harness the power of Python's data visualization capabilities and see for yourself how you can see even complex narrative structures at a glance. Installing VS CODE - Windows This post will get you started down that path. Good luck!

Similar Posts