绘图中坐标轴顺序不正确

3

我一直在尝试使用坐标来显示一个区域。 当我将坐标直接输入到列表中时,它可以显示该区域, 但是,当我使用变量时,则无法显示。

#plotting a triangle using coordinates
print('Enter the coordinates')
Na = input('Northings of A = ')
Ea = input('Eastings of A = ')

Nb = input('Northings of B = ')
Eb = input('Eastings of B = ')

Nc = input('Northings of C = ')
Ec = input('Eastings of C = ')

import matplotlib.pyplot as plt
x = [Ea, Eb, Ec, Ea]
y = [Na, Nb, Nc, Na]
plt.plot(x, y, 'yellow')
plt.show()


x = [1500, 1720, 1244.52, 1500]
y = [5930.15, 6230.25, 3254.62, 5960.15]
plt.plot(x, y, 'purple')
plt.show()

2
你能否提供列表x和y中的值? - gbajson
2
input() 返回字符串,你需要将变量的内容转换为数字类型才能得到所需的输出。 - Diziet Asahi
1
@gbajson 上面显示了这些值。 - Slwd-wave540
@DizietAsahi 谢谢 - Slwd-wave540
1个回答

2
我认为从输入中转换为整数是一个问题,并且缺少Nd和Ed变量。"Original Answer"翻译成"最初的回答"。
print('Enter the coordinates')
Na = input('Northings of A = ')
Ea = input('Eastings of A = ')
Nb = input('Northings of B = ')
Eb = input('Eastings of B = ')
Nc = input('Northings of C = ')
Ec = input('Eastings of C = ')
Nd = input('Northings of D = ')
Ed = input('Eastings of D = ')
import matplotlib.pyplot as plt
x = [int(Ea), int(Eb), int(Ec), int(Ed)]
y = [int(Na), int(Nb), int(Nc), int(Nd)]
plt.plot(x, y, 'green')
plt.show()
x = [1500, 1720, 1244.52, 1500]
y = [5930.15, 6230.25, 3254.62, 5960.15]
plt.plot(x, y, 'purple')
plt.show()

非常感谢你! - Slwd-wave540

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接