Need help displaying text underneath bar on an tkinter embedded matpotlib bar graph

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 2inshix
    New Member
    • May 2010
    • 11

    Need help displaying text underneath bar on an tkinter embedded matpotlib bar graph

    I was successful on embedding a matpotlib bar graph onto tkinter, however I can seem to find a way to disply text underneat each bar. The desired result would be text displaying the content of each bar underneath, for example
    bar 1, bar 2, bar 3, bar 4, bar 5, any help would be greatly apperciated.

    Happy holidays to all the programming community!

    Code:
    #!/usr/bin/env python
    import matplotlib
    matplotlib.use('TkAgg')
    import numpy as np
    import matplotlib.pyplot as plt
    from numpy import arange, sin, pi
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
    from matplotlib.figure import Figure
    from Tkinter import Tk, Frame, Menu
    import sys
    if sys.version_info[0] < 3:
        import Tkinter as Tk
    else:
        import tkinter as Tk
        
    def sabina():
        print "Sabina"
        
    def saoPaulo():
        print "Sao Paulo"
    
    def NSMX():
        print "NSMX"
    def knob():
        print "KNOB"
    def pointer():
        print "POINTER"
    def ambient():
        print "AMBIENT"
        
    class Example(Frame):
      
        def __init__(self, parent):
            Frame.__init__(self, parent)   
             
            self.parent = parent
            
            self.initUI()
            
        def initUI(self):
          
            self.parent.title("Submenu")
            
            menubar = Menu(self.parent)
            self.parent.config(menu=menubar)
            
            customers = Menu(menubar)       
            customers.add_command(label='Sabina', underline=0, command=sabina)
            customers.add_command(label='Sao Paulo', underline=0, command=saoPaulo)
            customers.add_command(label='NSMX', underline=0, command=NSMX)
            customers.add('separator')        
            customers.add_command(label="Exit", underline=0, command=self.onExit)
    
    
    
            menuProducts = Menu(menubar)       
            menuProducts.add_command(label='Knob', underline=0, command=knob)
            menuProducts.add_command(label='Pointer', underline=0, command=pointer)
            menuProducts.add_command(label='Ambient', underline=0, command=ambient)
            menuProducts.add('separator')        
            menuProducts.add_command(label="Exit", underline=0, command=self.onExit)      
    
            menuMaq = Menu(menubar)       
            menuMaq.add_command(label='Sabina', underline=0, command=sabina)
            menuMaq.add_command(label='Sao Paulo', underline=0, command=saoPaulo)
            menuMaq.add_command(label='NSMX', underline=0, command=NSMX)
            menuMaq.add('separator')        
            menuMaq.add_command(label="Exit", underline=0, command=self.onExit)
    
            menubar.add_cascade(label="Customers", underline=0, menu=customers)        
            menubar.add_cascade(label="Products", underline=0, menu=menuProducts)                  
    
        def onExit(self):
            self.quit()
    
    
    def destroy(e): sys.exit()
    
    root = Tk.Tk()
    root.wm_title("Produccion Status")
    #root.bind("<Destroy>", destroy)
    prodName='Model name'
    pO=19000
    po=[19000,19000,19000,19000,19000]
    N = ['Cap', 'bush', 'pointer', 'omori', 'KanseiHin']
    existencias   = [10000, 2000, 1100, 3500,3000]
    retrasos = [int(pO-existencias[0]),int(pO-existencias[1]),\
                int(pO-existencias[2]),int(pO-existencias[3]),int(pO-existencias[4])]#[5000, 8200, 9400, 2000]
    ind = np.arange(len(N))    # the x locations for the groups
    width = .80      # the width of the bars: can also be len(x) sequence
    
    f = Figure(figsize=(3,3), dpi=150)#window size
    a = f.add_subplot(111)#layout
    #t = arange(00,10,001)#xticks
    #s = sin(2*pi*t)
    a.bar(ind, po,   width, color='r')
    a.bar(ind, existencias,   width, color='y')
    #a.bar(ind, retrasos,   width, color='r')
    a.set_title(prodName)
    #ylabel('Cantidades')
    #title('Nombre del Modelo')
    a.set_xticks(ind+width/2., ('Cap', 'bush', 'pointer', 'omori', 'KanseiHin') )
    a.set_yticks(np.arange(0,20000,1000))
    a.set_xlabel('buhin')
    a.set_ylabel('Cantidades')
    
    
    # a tk.DrawingArea
    canvas = FigureCanvasTkAgg(f, master=root)
    canvas.show()
    #canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
    
    #toolbar = NavigationToolbar2TkAgg( canvas, root )
    #toolbar.update()
    canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
    
    button = Tk.Button(master=root, text='Quit', command=sys.exit)
    button.pack(side=Tk.BOTTOM)
    app = Example(root)
    app1 = Example(root)
    Tk.mainloop()
Working...