簡體   English   中英

如何在 tkinter 應用程序中操作 matplotlib 軸標簽間隔

[英]How to manipulate matplotlib axis-label intervals in an tkinter application

我想在我的 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)
        '''

在此處輸入圖片說明

有人能告訴我如何更改軸標簽上顯示的數據間隔嗎?

非常感謝和親切的問候

馬塞爾

嘿,我認為這回答了您的問題: 在 matplotlib 中更改 x 或 y 軸上的“滴答頻率”?

有多種方法可以做到這一點,請更詳細地檢查它所涵蓋的鏈接

嘗試這個:

 Import numpy as np

 a.xticks(np.arange(min((EUR_CAD_dates), max((EUR_CAD_dates)+1, 5.0))

 a.yticks(np.arange(min((EUR_CAD_closeBid), max((EUR_CAD_closeBid)+1, 5.0))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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