plotter_1.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. def graphPlot(workspace, again, tokens):
  2. """Function for plotting graphs in 2D and 3D space
  3. 2D graphs are plotted for expression in one variable and equations in two variables. 3D graphs are plotted for expressions in two variables and equations in three variables.
  4. Arguments:
  5. workspace {QtWidgets.QWidget} -- main layout
  6. Returns:
  7. graphVars {list} -- variables to be plotted on the graph
  8. func {numpy.array(2D)/function(3D)} -- equation converted to compatible data type for plotting
  9. variables {list} -- variables in given equation
  10. again {bool} -- True when an equation can be plotted in 2D and 3D both else False
  11. Note:
  12. The func obtained from graphPlot() function is of different type for 2D and 3D plots. For 2D, func is a numpy array, and for 3D, func is a function.
  13. """
  14. if tokens is None:
  15. axisRange = workspace.axisRange
  16. tokens = workspace.eqToks[-1]
  17. else:
  18. axisRange = [10, 10, 10, 30]
  19. eqType = getTokensType(tokens)
  20. LHStok, RHStok = getLHSandRHS(tokens)
  21. variables = sorted(getVariables(LHStok, RHStok))
  22. dim = len(variables)
  23. if (dim == 1) or ((dim == 2) and eqType == "equation"):
  24. if again:
  25. variables.append('f(' + variables[0] + ')')
  26. graphVars, func = plotIn3D(LHStok, RHStok, variables, axisRange)
  27. else:
  28. graphVars, func = plotIn2D(LHStok, RHStok, variables, axisRange)
  29. if dim == 1:
  30. variables.append('f(' + variables[0] + ')')
  31. elif (dim == 2 and eqType == "expression") or ((dim == 3) and eqType == "equation"):
  32. graphVars, func = plotIn3D(LHStok, RHStok, variables, axisRange)
  33. if dim == 2:
  34. variables.append('f(' + variables[0] + ',' + variables[1] + ')')
  35. else:
  36. return [], None, None
  37. return graphVars, func, variables