簡體   English   中英

您如何將列表 [x, y] 坐標表示為 python 上的圖形?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM