如何在tkinter应用程序中操作matplotlib轴标签间隔

时间:2018-02-13 01:03:49

标签: python tkinter

我想在我的tkinter应用程序中使用matplotlib图,到目前为止一切正常。唯一的问题是,x和y轴上的数据间隔太高。如果轴上只显示每五个数据点,我更愿意。

def animate(i):  # animate function for matplotlib

    import csv
    import os

    EUR_CAD_closeBid = []
    EUR_CAD_dates = []

    path = os.path.join('EUR_CAD')

    with open('EUR_CAD.csv', 'r') as csvfile:

        readCSV = csv.reader(csvfile, delimiter=',', quotechar='|')

        for row in readCSV:

            closeBid = row[0]
            dates = row[1]

            EUR_CAD_closeBid.append(closeBid)
            EUR_CAD_dates.append(dates)



    a.clear()
    a.plot(EUR_CAD_dates,EUR_CAD_closeBid, "r", label="bid")
    a.legend()

    title = "EUR/USD\nLast Price:"+str(EUR_CAD_closeBid[-1])
    a.set_title(title)


class PageTwo(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text="Graph Page", font=LARGE_FONT)
        label.pack(pady=10,padx=10)

        button1 = ttk.Button(self, text="Back to Home", command=lambda:controller.show_frame(StartPage))
        button1.pack()

        #Build Canvas for matplotlib chart
        canvas = FigureCanvasTkAgg(f,self)
        canvas.show()
        canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand = True)

        # chart toolbar
        '''
        toolbar = NavigationToolbar2TkAgg(canvas, self)
        toolbar.update()
        canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand = True)
        '''

enter image description here

有人能告诉我如何更改轴标签上显示的数据间隔吗?

非常感谢和亲切的问候

马塞尔

1 个答案:

答案 0 :(得分:1)

嘿,我认为这回答了你的问题:Changing the "tick frequency" on x or y axis in matplotlib?

有多种方法可以执行此操作,请查看更详细的链接d

试试这个:

void **items