python - Displaying a matplotlib bar chart in Tkinter -


i trying display matplotlib bar chart in tkinter window. have found plenty of tutorials on how put line chart in, such this: http://matplotlib.org/examples/user_interfaces/embedding_in_tk.html

but can't find 1 putting in bar chart. way know make bar chart this: http://matplotlib.org/examples/api/barchart_demo.html. obviously, modules imported in bar chart example not same ones in tkinter examples, , i'm not sure how make work, if can @ all.

long story short, can provide me example of matplotlib bar chart being displayed inside tkinter window? thanks.

for may wondering in future, figured out how work. basically, bar chart has on figure figurecanvastkagg can generate widget tkinter use. had assumed needed use pyplot, isn't true. came with:

import matplotlib, numpy, sys matplotlib.use('tkagg') matplotlib.backends.backend_tkagg import figurecanvastkagg matplotlib.figure import figure if sys.version_info[0] < 3:     import tkinter tk else:     import tkinter tk  root = tk.tk()  f = figure(figsize=(5,4), dpi=100) ax = f.add_subplot(111)  data = (20, 35, 30, 35, 27)  ind = numpy.arange(5)  # x locations groups width = .5  rects1 = ax.bar(ind, data, width)  canvas = figurecanvastkagg(f, master=root) canvas.show() canvas.get_tk_widget().pack(side=tk.top, fill=tk.both, expand=1)  tk.mainloop() 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -