zoukankan      html  css  js  c++  java
  • tkinter matplotlib numpy pandas line charts

    # 8 organize your code
    import matplotlib
    matplotlib.use('TkAgg')
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
    from matplotlib.figure import Figure
    import matplotlib.animation as animation
    from matplotlib import style
    
    import Tkinter as tk
    import ttk
    
    import urllib
    import json
    
    import pandas as pd
    import numpy as np
    
    LARGE_FONT = ('Vernada', 12)
    style.use('ggplot')
    
    f = Figure(figsize=(5, 5), dpi=100)
    a = f.add_subplot(111)
    ##a.plot([1,2,3,4,5,6 ,7,8], [5,6,1,3,8,9,3,5])
    
    def animate(i):
        pullData = open('sampleData.txt', 'r').read()
        dataList = pullData.split('
    ')
        xList = []
        yList = []
        for eachLine in dataList:
            if len(eachLine) > 1:
                x, y = eachLine.split(',')
                xList.append(int(x)) 
                yList.append(int(y))
    
        a.clear()
        a.plot(xList, yList)
    
         
    
    class SeaofBTCapp(tk.Tk):
    
        def __init__(self, *args, **kwargs):
    
            tk.Tk.__init__(self)
    
            tk.Tk.iconbitmap(self, default="consumer.ico")
            tk.Tk.wm_title(self, "Sea of BTC client")
            
            container = tk.Frame(self)
            container.pack(side='top', fill='both', expand=True)
            container.grid_rowconfigure(0, weight=1)
            container.grid_columnconfigure(0, weight=1)
    
            self.frames = {}
            for F in (StartPage, PageOne, PageTwo, PageThree):
                frame = F(container, self)
    
                self.frames[F] = frame
    
                frame.grid(row=0, column=0, sticky='nsew')
    
            self.show_frame(StartPage)
    
        def show_frame(self, cont):
    
            frame = self.frames[cont]
            frame.tkraise()
    
    
    class StartPage(tk.Frame):
    
        def __init__(self, parent, controller):
            tk.Frame.__init__(self, parent)
            label = tk.Label(self, text='Start Page', font=LARGE_FONT)
            label.pack(padx=10, pady=10)
    
            button = ttk.Button(self, text="Visit Page 1",
                               command=lambda: controller.show_frame(PageOne))
            button.pack()
            button1 = tk.Button(self, text="Back to Page Two",
                               command=lambda: controller.show_frame(PageTwo))
            button1.pack()
            button2 = tk.Button(self, text="Graph Page",
                               command=lambda: controller.show_frame(PageThree))
            button2.pack()
    
    
    class PageOne(tk.Frame):
        def __init__(self, parent, controller):
            tk.Frame.__init__(self, parent)
            label = tk.Label(self, text="Page One", font=LARGE_FONT)
            label.pack(padx=10, pady=10)
    
            button = tk.Button(self, text="Back to Start Page",
                               command=lambda: controller.show_frame(StartPage))
            button.pack()
    
            button1 = tk.Button(self, text="Back to Page Two",
                               command=lambda: controller.show_frame(PageTwo))
            button1.pack()
    
    class PageTwo(tk.Frame):
        def __init__(self, parent, controller):
            tk.Frame.__init__(self, parent)
            label = tk.Label(self, text="Page Two!!!", font=LARGE_FONT)
            label.pack(padx=10, pady=10)
    
            button = tk.Button(self, text="Back to Start Page",
                               command=lambda: controller.show_frame(StartPage))
            button.pack()
    
            button1 = tk.Button(self, text="Back to Page One",
                               command=lambda: controller.show_frame(PageOne))
            button1.pack()
    
    class PageThree(tk.Frame):
        def __init__(self, parent, controller):
            tk.Frame.__init__(self, parent)
            label = tk.Label(self, text="Graph Page!!!", font=LARGE_FONT)
            label.pack(padx=10, pady=10)
    
            button = tk.Button(self, text="Back to Start Page",
                               command=lambda: controller.show_frame(StartPage))
            button.pack()
    
            canvas = FigureCanvasTkAgg(f, self)
            canvas.show()
            canvas.get_tk_widget().pack(side='top', fill='both', expand=True)
    
            toolbar = NavigationToolbar2TkAgg(canvas, self)
            toolbar.update()
            canvas._tkcanvas.pack(side='top', fill='both', expand=True)
    
    app = SeaofBTCapp()
    ani = animation.FuncAnimation(f, animate, interval=1000)
    app.mainloop()
    
    
    
    
    
    
  • 相关阅读:
    泛型
    HDU 4917 Permutation
    OC本学习笔记Foundation框架NSString与NSMutableString
    HDU 5095 Linearization of the kernel functions in SVM(模拟)
    大约Java有点感悟---开发商根本上感悟学习
    Codeforces 442B Andrey and Problem(贪婪)
    mysql数据库优化课程---15、mysql优化步骤(mysql中最常用最立竿见影的优化是什么)
    mysql数据库优化课程---14、常用的sql技巧
    mysql数据库优化课程---13、mysql基础操作(mysql如何复制表)
    mysql数据库优化课程---12、mysql嵌套和链接查询(查询user表中存在的所有班级的信息?)
  • 原文地址:https://www.cnblogs.com/otfsenter/p/6551656.html
Copyright © 2011-2022 走看看