![](/img/trans.png)
[英]how to plot a networkx graph using the (x,y) coordinates of the points list?
[英]How do you represent a list [x, y] coordinates into a graph on python?
我當前的輸出是這樣設置的
[2, 9]
[2, 8]
[2, 7]
[3, 7]
我希望它顯示在 20x20 的網格上
從您的問題看來,您希望將輸出繪制為 20x20 網格上的散點圖。 您需要使用matplotlib
包( pip install matplotlib
應該可以工作)。 如果將輸出保存為列表列表,則可以像這樣使用列表推導:
import matplotlib.pyplot as plt
# You'll need to figure out how to save your output this way
points = [[2, 9], [2, 8], [2, 7], [3, 7]]
# setting the window to be [0, 20]
plt.xlim([0, 20])
plt.ylim([0, 20])
# plot the graph
plt.scatter(x=[x[0] for x in points], y=[y[1] for y in points])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.