Skip to content

Commit

Permalink
Added separate tabs for 2D and 3D plots
Browse files Browse the repository at this point in the history
  • Loading branch information
WiCK3D-POiSON committed Aug 9, 2018
1 parent d798f46 commit 85e01e4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 27 deletions.
26 changes: 13 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from visma.io.checks import checkTypes, getVariables
from visma.io.tokenize import tokenizer, getLHSandRHS
from visma.io.parser import resultLatex
from visma.gui.plotter import plotFigure, plot
from visma.gui.plotter import plotFigure2D, plotFigure3D, plot
from visma.gui.qsolver import quickSimplify, qSolveFigure, showQSolve
from visma.gui.settings import preferenceLayout
from visma.gui.steps import stepsFigure, showSteps
Expand Down Expand Up @@ -148,24 +148,24 @@ def initUI(self):
buttonSpace.setFixedWidth(300)
buttonSpace.setStatusTip("Interact")

tabPlot = QTabWidget()
tabPlot.tab1 = QWidget()
tabPlot.tab2 = QWidget()
tabPlot.addTab(tabPlot.tab1, "plotter")
tabPlot.addTab(tabPlot.tab2, "settings")
tabPlot.tab1.setLayout(plotFigure(self))
tabPlot.tab1.setStatusTip("Visualize graph")
# tabPlot.tab2.setLayout(plotPref(self))
tabPlot.tab2.setStatusTip("Plot Preferences")
self.tabPlot = QTabWidget()
self.tabPlot.tab1 = QWidget()
self.tabPlot.tab2 = QWidget()
self.tabPlot.addTab(self.tabPlot.tab1, "2D-plot")
self.tabPlot.addTab(self.tabPlot.tab2, "3D-plot")
self.tabPlot.tab1.setLayout(plotFigure2D(self))
self.tabPlot.tab1.setStatusTip("Visualize equation in 2D")
self.tabPlot.tab2.setLayout(plotFigure3D(self))
self.tabPlot.tab2.setStatusTip("Visualize equation in 3D")

tabStepsLogs = QTabWidget()
tabStepsLogs.tab1 = QWidget()
tabStepsLogs.tab2 = QWidget()
tabStepsLogs.addTab(tabStepsLogs.tab1, "step-by-step")
tabStepsLogs.addTab(tabStepsLogs.tab2, "settings")
# tabStepsLogs.addTab(tabStepsLogs.tab2, "logger")
tabStepsLogs.tab1.setLayout(stepsFigure(self))
tabStepsLogs.tab1.setStatusTip("Step-by-step solver")
tabStepsLogs.tab2.setStatusTip("Steps Figure Preferences")
# tabStepsLogs.tab2.setStatusTip("Logger")

font = QtGui.QFont()
font.setPointSize(16)
Expand All @@ -192,7 +192,7 @@ def initUI(self):

splitter2 = QSplitter(Qt.Horizontal)
splitter2.addWidget(tabStepsLogs)
splitter2.addWidget(tabPlot)
splitter2.addWidget(self.tabPlot)
splitter2.addWidget(self.equationList)

splitter1 = QSplitter(Qt.Vertical)
Expand Down
57 changes: 43 additions & 14 deletions visma/gui/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def graphPlot(workspace):
LHStok, RHStok = getLHSandRHS(tokens)
variables = sorted(getVariables(LHStok, RHStok))
dim = len(variables)
if (dim == 1 and eqType == "expression") or (dim == 2 and eqType == "equation"):
if (dim == 1 and eqType == "expression") or ((dim == 2) and eqType == "equation"):
graphVars, func = plotIn2D(LHStok, RHStok, variables, axisRange)
if dim == 1:
variables.append('f(' + variables[0] + ')')
elif (dim == 2 and eqType == "expression") or (dim == 3 and eqType == "equation"):
elif (dim == 2 and eqType == "expression") or ((dim == 3) and eqType == "equation"):
graphVars, func = plotIn3D(LHStok, RHStok, variables, axisRange)
if dim == 2:
variables.append('f(' + variables[0] + ',' + variables[1] + ')')
Expand Down Expand Up @@ -166,7 +166,7 @@ def getFuncExpr(exprTok, eqnVars, graphVars):
#######


def plotFigure(workspace):
def plotFigure2D(workspace):
"""GUI layout for plot figure
Arguments:
Expand All @@ -175,17 +175,40 @@ def plotFigure(workspace):
Returns:
layout {QtWidgets.QVBoxLayout} -- contains matplot figure
"""
workspace.figure = Figure()
workspace.canvas = FigureCanvas(workspace.figure)
# workspace.figure.patch.set_facecolor('white')
workspace.figure2D = Figure()
workspace.canvas2D = FigureCanvas(workspace.figure2D)
# workspace.figure2D.patch.set_facecolor('white')

class NavigationCustomToolbar(NavigationToolbar):
toolitems = [t for t in NavigationToolbar.toolitems if t[0] in ()]

workspace.toolbar = NavigationCustomToolbar(workspace.canvas, workspace)
workspace.toolbar2D = NavigationCustomToolbar(workspace.canvas2D, workspace)
layout = QVBoxLayout()
layout.addWidget(workspace.canvas)
layout.addWidget(workspace.toolbar)
layout.addWidget(workspace.canvas2D)
layout.addWidget(workspace.toolbar2D)
return layout


def plotFigure3D(workspace):
"""GUI layout for plot figure
Arguments:
workspace {QtWidgets.QWidget} -- main layout
Returns:
layout {QtWidgets.QVBoxLayout} -- contains matplot figure
"""
workspace.figure3D = Figure()
workspace.canvas3D = FigureCanvas(workspace.figure3D)
# workspace.figure3D.patch.set_facecolor('white')

class NavigationCustomToolbar(NavigationToolbar):
toolitems = [t for t in NavigationToolbar.toolitems if t[0] in ()]

workspace.toolbar3D = NavigationCustomToolbar(workspace.canvas3D, workspace)
layout = QVBoxLayout()
layout.addWidget(workspace.canvas3D)
layout.addWidget(workspace.toolbar3D)
return layout


Expand All @@ -197,22 +220,26 @@ def plot(workspace):
Arguments:
workspace {QtWidgets.QWidget} -- main layout
"""
workspace.figure2D.clear()
workspace.figure3D.clear()
graphVars, func, variables = graphPlot(workspace)
workspace.figure.clf()
if len(graphVars) == 2:
X, Y = graphVars[0], graphVars[1]
ax = workspace.figure.add_subplot(111)
ax = workspace.figure2D.add_subplot(111)
ax.clear()
ax.contour(X, Y, func, [0])
ax.grid()
ax.set_xlabel(r'$' + variables[0] + '$')
ax.set_ylabel(r'$' + variables[1] + '$')
workspace.figure.set_tight_layout({"pad": 1}) # removes extra padding
workspace.figure2D.set_tight_layout({"pad": 1}) # removes extra padding
workspace.canvas2D.draw()
workspace.tabPlot.setCurrentIndex(0)
workspace.tabPlot.setTabEnabled(1, False)
elif len(graphVars) == 3:
xrange = graphVars[0]
yrange = graphVars[1]
zrange = graphVars[2]
ax = Axes3D(workspace.figure)
ax = Axes3D(workspace.figure3D)
for z in zrange:
X, Y = np.meshgrid(xrange, yrange)
Z = func(X, Y, z)
Expand All @@ -238,7 +265,9 @@ def plot(workspace):
ax.set_xlabel(r'$' + variables[0] + '$')
ax.set_ylabel(r'$' + variables[1] + '$')
ax.set_zlabel(r'$' + variables[2] + '$')
workspace.canvas.draw()
workspace.canvas3D.draw()
workspace.tabPlot.setCurrentIndex(1)
workspace.tabPlot.setTabEnabled(0, False)


def refreshPlot(workspace):
Expand Down

0 comments on commit 85e01e4

Please sign in to comment.