FraudSentinelX / pilot_graph
yekkala's picture
Update pilot_graph
293b791 verified
raw
history blame contribute delete
553 Bytes
from PIL import Image
import io
import matplotlib.pyplot as plt
import networkx as nx
def plot_graph(self, G):
plt.figure(figsize=(3, 2))
nx.draw(G, with_labels=True, node_color="lightblue", font_weight="bold")
plt.axis("off")
plt.tight_layout()
# Save the figure to a BytesIO buffer
buf = io.BytesIO()
plt.savefig(buf, format="png")
plt.close()
# Move to the beginning of the buffer before reading
buf.seek(0)
# Load the image from the buffer into a PIL Image
image = Image.open(buf)
return image