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

I want to use a matplotlib graph in my tkinter application and so far everything works. The only problem is, that the data intervals on the x and y axis are too high. I would prefer if only every fifth data point is being shown on the axis.

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]


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

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

class PageTwo(tk.Frame):

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

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

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

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

enter image description here

Can someone tell me how to change the intervals of the data displayed on the axis lables?

Thanks a lot and kind regards


1 answer

  • answered 2018-02-13 08:37 Moller Rodrigues

    Hey there I think this answers your question: Changing the "tick frequency" on x or y axis in matplotlib?

    There are multiple ways to do this please check the link it is cover d in more detail

    Try this:

     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))