【发布时间】:2019-08-09 07:23:47
【问题描述】:
matplotlib绘制的图表的轴在绘制某些点后变得不按数字顺序
只是想编写一个程序来绘制和连接图表上的点以掌握matplotlib 和tkinter 的窍门
from tkinter import *
import matplotlib.pyplot as plt
root = Tk()
x_points = []
y_points = []
def plot():
global x_points
global y_points
x = entry_x.get()
y = entry_y.get()
x_points.append(x)
y_points.append(y)
plt.plot(x_points,y_points)
plt.show()
prompt_x = Label(root, text = 'enter the x coordinate')
prompt_y = Label(root, text = 'enter the y coordinate')
button = Button(text = 'click to plot point', command = plot)
entry_x = Entry()
entry_y = Entry()
prompt_x.grid(row = 0)
prompt_y.grid(row = 1)
entry_x.grid(row = 0, column = 1)
entry_y.grid(row = 1, column = 1)
button.grid(row=2)
plt.show()
root.mainloop()
按顺序绘制点:
(1,2)
(2,5)
(1.5,3)
我希望它形成一个triangle,
但导致线条只是改变颜色并将轴拧紧
【问题讨论】:
-
如果你像这样绘制:
plt.plot([1, 2, 1.5], [2, 5, 3]);plt.show(),你会得到图表上的线。 “拧轴”是什么意思?请附上你得到的图表。
标签: python matplotlib