473,407 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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

11
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!

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/env python
  2. import matplotlib
  3. matplotlib.use('TkAgg')
  4. import numpy as np
  5. import matplotlib.pyplot as plt
  6. from numpy import arange, sin, pi
  7. from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
  8. from matplotlib.figure import Figure
  9. from Tkinter import Tk, Frame, Menu
  10. import sys
  11. if sys.version_info[0] < 3:
  12.     import Tkinter as Tk
  13. else:
  14.     import tkinter as Tk
  15.  
  16. def sabina():
  17.     print "Sabina"
  18.  
  19. def saoPaulo():
  20.     print "Sao Paulo"
  21.  
  22. def NSMX():
  23.     print "NSMX"
  24. def knob():
  25.     print "KNOB"
  26. def pointer():
  27.     print "POINTER"
  28. def ambient():
  29.     print "AMBIENT"
  30.  
  31. class Example(Frame):
  32.  
  33.     def __init__(self, parent):
  34.         Frame.__init__(self, parent)   
  35.  
  36.         self.parent = parent
  37.  
  38.         self.initUI()
  39.  
  40.     def initUI(self):
  41.  
  42.         self.parent.title("Submenu")
  43.  
  44.         menubar = Menu(self.parent)
  45.         self.parent.config(menu=menubar)
  46.  
  47.         customers = Menu(menubar)       
  48.         customers.add_command(label='Sabina', underline=0, command=sabina)
  49.         customers.add_command(label='Sao Paulo', underline=0, command=saoPaulo)
  50.         customers.add_command(label='NSMX', underline=0, command=NSMX)
  51.         customers.add('separator')        
  52.         customers.add_command(label="Exit", underline=0, command=self.onExit)
  53.  
  54.  
  55.  
  56.         menuProducts = Menu(menubar)       
  57.         menuProducts.add_command(label='Knob', underline=0, command=knob)
  58.         menuProducts.add_command(label='Pointer', underline=0, command=pointer)
  59.         menuProducts.add_command(label='Ambient', underline=0, command=ambient)
  60.         menuProducts.add('separator')        
  61.         menuProducts.add_command(label="Exit", underline=0, command=self.onExit)      
  62.  
  63.         menuMaq = Menu(menubar)       
  64.         menuMaq.add_command(label='Sabina', underline=0, command=sabina)
  65.         menuMaq.add_command(label='Sao Paulo', underline=0, command=saoPaulo)
  66.         menuMaq.add_command(label='NSMX', underline=0, command=NSMX)
  67.         menuMaq.add('separator')        
  68.         menuMaq.add_command(label="Exit", underline=0, command=self.onExit)
  69.  
  70.         menubar.add_cascade(label="Customers", underline=0, menu=customers)        
  71.         menubar.add_cascade(label="Products", underline=0, menu=menuProducts)                  
  72.  
  73.     def onExit(self):
  74.         self.quit()
  75.  
  76.  
  77. def destroy(e): sys.exit()
  78.  
  79. root = Tk.Tk()
  80. root.wm_title("Produccion Status")
  81. #root.bind("<Destroy>", destroy)
  82. prodName='Model name'
  83. pO=19000
  84. po=[19000,19000,19000,19000,19000]
  85. N = ['Cap', 'bush', 'pointer', 'omori', 'KanseiHin']
  86. existencias   = [10000, 2000, 1100, 3500,3000]
  87. retrasos = [int(pO-existencias[0]),int(pO-existencias[1]),\
  88.             int(pO-existencias[2]),int(pO-existencias[3]),int(pO-existencias[4])]#[5000, 8200, 9400, 2000]
  89. ind = np.arange(len(N))    # the x locations for the groups
  90. width = .80      # the width of the bars: can also be len(x) sequence
  91.  
  92. f = Figure(figsize=(3,3), dpi=150)#window size
  93. a = f.add_subplot(111)#layout
  94. #t = arange(00,10,001)#xticks
  95. #s = sin(2*pi*t)
  96. a.bar(ind, po,   width, color='r')
  97. a.bar(ind, existencias,   width, color='y')
  98. #a.bar(ind, retrasos,   width, color='r')
  99. a.set_title(prodName)
  100. #ylabel('Cantidades')
  101. #title('Nombre del Modelo')
  102. a.set_xticks(ind+width/2., ('Cap', 'bush', 'pointer', 'omori', 'KanseiHin') )
  103. a.set_yticks(np.arange(0,20000,1000))
  104. a.set_xlabel('buhin')
  105. a.set_ylabel('Cantidades')
  106.  
  107.  
  108. # a tk.DrawingArea
  109. canvas = FigureCanvasTkAgg(f, master=root)
  110. canvas.show()
  111. #canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
  112.  
  113. #toolbar = NavigationToolbar2TkAgg( canvas, root )
  114. #toolbar.update()
  115. canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
  116.  
  117. button = Tk.Button(master=root, text='Quit', command=sys.exit)
  118. button.pack(side=Tk.BOTTOM)
  119. app = Example(root)
  120. app1 = Example(root)
  121. Tk.mainloop()
  122.  
Dec 19 '12 #1
0 1370

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: WOJSAL | last post by:
I want show HTML-text (messages, textarea etc.) with TkInter. What free package, module i need? Please help. -- Regards
2
by: John B. | last post by:
I'm using <h1>MY HEADING</h1> to display a title, however I would like to show one short line of text beside it<p>The short line of text</p>, and then go back to normal. Here's an example of how...
7
by: William Gill | last post by:
Is there a simple way to cut and paste from a tkinter text widget to an entry widget? I know I could create a mouse button event that triggers a popup (message widget) prompting for cut/paste in...
9
by: Susan Bricker | last post by:
Greetings. I am having trouble populating text data that represents data in my table. Here's the setup: There is a People Table (name, address, phone, ...) peopleID = autonumber key There...
3
by: Ron Vecchi | last post by:
I have a text file(.js) that holds a buch of java script code that is rendered in some web controls all part of a larger webcontrol library. The file is rather large. Would embedding this...
0
by: doctorle | last post by:
I use Access XP (2002) and have had no problem designing forms, reports and displaying data in Unicode (Vietnamese). But Unicode strings fail to display properly inside charts (MS Graph 8 object)....
2
by: sj | last post by:
I am just learning to use Tkinter and am having problems displaying image files. I am able to display an image using tutorials (such as http://www.daniweb.com/code/snippet296.html) But when I try...
0
by: paragguptaiiita | last post by:
I have one problem regarding displaying text from XML file. I have a XSL variable named $p = (0 0 0) (0.82 0 0) (1.63 -0.01 0) (2.63 -0.01 0) (3.63 -0.01 0) (4.63 -0.01 0) (5.63 -0.02 0) (6.63 -0.02...
0
by: paragguptaiiita | last post by:
I have one problem regarding displaying text from XML file. I have a XSL variable named $p = (0 0 0) (0.82 0 0) (1.63 -0.01 0) (2.63 -0.01 0) (3.63 -0.01 0) (4.63 -0.01 0) (5.63 -0.02 0) (6.63 -0.02...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.