1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- def renderPlot(workspace, graphVars, func, variables, tokens=None):
- """Renders plot for functions in 2D and 3D
- Maps points from the numpy arrays for variables in given equation on the 2D/3D plot figure
- Arguments:
- workspace {QtWidgets.QWidget} -- main layout
- graphVars {list} -- variables for plotting
- dim {int} -- dimenion of plot
- variables {list} -- variables in equation
- """
- if len(graphVars) == 2:
- X, Y = graphVars[0], graphVars[1]
- 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.figure2D.set_tight_layout({"pad": 1}) # removes extra padding
- workspace.canvas2D.draw()
- workspace.tabPlot.setCurrentIndex(0)
- elif len(graphVars) == 3:
- xrange = graphVars[0]
- yrange = graphVars[1]
- zrange = graphVars[2]
- ax = Axes3D(workspace.figure3D)
- for z in zrange:
- X, Y = np.meshgrid(xrange, yrange)
- Z = func(X, Y, z)
- ax.contour(X, Y, Z + z, [z], zdir='z')
- for y in yrange:
- X, Z = np.meshgrid(xrange, zrange)
- Y = func(X, y, Z)
- ax.contour(X, Y + y, Z, [y], zdir='y')
- for x in xrange:
- Y, Z = np.meshgrid(yrange, zrange)
- X = func(x, Y, Z)
- ax.contour(X + x, Y, Z, [x], zdir='x')
- if tokens is None:
- axisRange = workspace.axisRange
- else:
- axisRange = [10, 10, 10, 30]
- xmin = -axisRange[0]
- xmax = axisRange[0]
- ymin = -axisRange[1]
- ymax = axisRange[1]
- zmin = -axisRange[2]
- zmax = axisRange[2]
- ax.set_xlim3d(xmin, xmax)
- ax.set_ylim3d(ymin, ymax)
- ax.set_zlim3d(zmin, zmax)
- ax.set_xlabel(r'$' + variables[0] + '$')
- ax.set_ylabel(r'$' + variables[1] + '$')
- ax.set_zlabel(r'$' + variables[2] + '$')
- workspace.canvas3D.draw()
- workspace.tabPlot.setCurrentIndex(1)
|