Skip to content

Commit

Permalink
basic matplotlib support (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarvisteach committed Feb 8, 2017
1 parent 14db7cb commit b61cd59
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
45 changes: 45 additions & 0 deletions appJar/appjar.py
Expand Up @@ -178,6 +178,7 @@ def CENTER(win):
PIECHART = 15
PROPERTIES = 16
GRID = 17
PLOTS = 18

RB = 60
CB = 40
Expand Down Expand Up @@ -562,6 +563,7 @@ def __initArrays(self):
self.n_tbButts = {}
self.n_spins = {}
self.n_props = {}
self.n_plots = {}
self.n_options = {}
self.n_frameLabs = {}
self.n_textAreas = {}
Expand Down Expand Up @@ -1377,6 +1379,8 @@ def __getItems(self, kind):
return self.n_pieCharts
elif kind == self.PROPERTIES:
return self.n_props
elif kind == self.PLOTS:
return self.n_plots
elif kind == self.GRID:
return self.n_grids

Expand Down Expand Up @@ -3409,6 +3413,47 @@ def setOptionBox(self, title, index, value=True):
var.set("")
self.warn("No items to select from: " + title)

#####################################
# FUNCTION for matplotlib
#####################################
def addPlot(
self,
title,
t, s,
row=None,
column=0,
colspan=0,
rowspan=0):
self.__verifyItem(self.n_plots, title, True)

from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure

fig = Figure()

axes = fig.add_subplot(111)
axes.plot(t,s)

canvas = FigureCanvasTkAgg(fig, self.__getContainer())
canvas.fig = fig
canvas.axes = axes
canvas.show()
# canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
canvas._tkcanvas.pack(side=TOP, fill=BOTH, expand=1)

self.__positionWidget(canvas.get_tk_widget(), row, column, colspan, rowspan)
self.n_plots[title] = canvas
return axes

def updatePlot(self, title, t, s):
canvas = self.__verifyItem(self.n_plots, title)

axes = canvas.axes
axes.clear()
axes.plot(t, s)
# canvas.draw()


#####################################
# FUNCTION to manage Properties Widgets
#####################################
Expand Down
23 changes: 23 additions & 0 deletions examples/plot.py
@@ -0,0 +1,23 @@
#import matplotlib
#matplotlib.use('TkAgg')
from numpy import arange, sin, pi
import sys
sys.path.append("../")
from appJar import gui

def press(btn):
t = arange(0.2, 12.0, 0.01)
s = sin(4*pi*t)
app.updatePlot("p1", t, s)

t = arange(0.0, 3.0, 0.01)
s = sin(2*pi*t)

app = gui()
app.startLabelFrame("MatPlotLib")
app.addLabel("l1", "Welcome to MatPlotLib")
axes = app.addPlot("p1", t, s)
axes.legend(['some stuff'])
app.addButtons(["Quit", "Open", "Close"], press)
app.stopLabelFrame()
app.go()

0 comments on commit b61cd59

Please sign in to comment.