Advertisement
UF6

Group Project 2,Problem 10

UF6
May 4th, 2016
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.07 KB | None | 0 0
  1. #Josh
  2. %matplotlib notebook
  3. from mpl_toolkits.mplot3d import axes3d
  4. import matplotlib.pyplot as plt
  5. import numpy as np
  6.  
  7. # Prepare the figure container
  8. fig = plt.figure()
  9. ax = axes3d.Axes3D(fig)
  10.  
  11. # Prepare the 2D domain: x from -1 to 1 and y from -1 to 1
  12. x,y = np.meshgrid(np.linspace(-3,3,41),np.linspace(-3,3,41))
  13. z = x*np.exp((-(x**2)/2)-((y**3)/3)+y)
  14.  
  15. # Plot the surface
  16. ax.plot_surface(x,y,z,rstride=1, cstride=1, cmap="jet", vmin=np.nanmin(z), vmax=np.nanmax(z), lw=1, antialiased=True)
  17.  
  18. # Set all labels, view, and then plot
  19. ax.set_xlabel('x')
  20. ax.set_ylabel('y')
  21. ax.set_zlabel('f(x,y)')
  22. ax.set_xticks([-3,-2,-1,0,1,2,3])
  23. ax.set_yticks([-3,-2,-1,0,1,2,3])
  24. ax.set_zticks([-3,-2,-1,0,1,2,3])
  25. ax.view_init(68,-140)
  26. plt.show()
  27.  
  28.  
  29. %matplotlib notebook
  30. from mpl_toolkits.mplot3d import axes3d
  31. import matplotlib.pyplot as plt
  32. import numpy as np
  33.  
  34. # Prepare the figure container
  35. fig = plt.figure()
  36. ax = axes3d.Axes3D(fig)
  37.  
  38. # Prepare the 2D domain: x from -1 to 1 and y from -1 to 1
  39. x,y = np.meshgrid(np.linspace(-3,3,41),np.linspace(-3,3,41))
  40. z = x*np.exp((-(x**2)/2)-((y**3)/3)+y)
  41.  
  42. flagoffx = np.logical_and(x >= 0, x <= 1)
  43. flagoffy = np.logical_and(y >= 0, y <= 1)
  44. flagoff = np.logical_and(flagoffx,flagoffy)
  45. z[flagoff] = np.nan
  46.  
  47. # Plot the surface
  48. ax.plot_surface(x,y,z,rstride=1, cstride=1, cmap="jet", vmin=np.nanmin(z), vmax=np.nanmax(z), lw=1, antialiased=True)
  49.  
  50. # Set all labels, view, and then plot
  51. ax.set_xlabel('x')
  52. ax.set_ylabel('y')
  53. ax.set_zlabel('f(x,y)')
  54. ax.set_xticks([-3,-2,-1,0,1,2,3])
  55. ax.set_yticks([-3,-2,-1,0,1,2,3])
  56. ax.set_zticks([-3,-2,-1,0,1,2,3])
  57. ax.view_init(68,-140)
  58. plt.show()
  59.  
  60.  
  61. %matplotlib notebook
  62. import matplotlib
  63. import matplotlib.pyplot as plt
  64. import numpy as np
  65.  
  66. # Prepare the figure container
  67. fig, ax = plt.subplots()
  68.  
  69. # Prepare the 2D domain: x from -1 to 1 and y from -1 to 1
  70. x,y = np.meshgrid(np.linspace(-3,3,41),np.linspace(-3,3,41))
  71. z = x*np.exp((-(x**2)/2)-((y**3)/3)+y)
  72.  
  73. # Plot the surface
  74. cnt = ax.contour(z, cmap=matplotlib.cm.RdBu, vmin=abs(z).min(), vmax=abs(z).max(), extent=[-3, 3, -3, 3])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement