Advertisement
mikhail_dvorkin

PyPlot Examples

Mar 28th, 2016
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.48 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. import random
  4. from mpl_toolkits.mplot3d import Axes3D
  5.  
  6.  
  7. def f(x, y):
  8.     return (1 - x / 2 + x ** 5 + y ** 3) * np.exp(-x **2 - y ** 2)
  9.  
  10. n = 200
  11. x = np.linspace(-3, 3, n)
  12. y = np.linspace(-3, 3, n)
  13. xgrid, ygrid = np.meshgrid(x, y)
  14. z = f(xgrid, ygrid)
  15.  
  16. # f = plt.figure()
  17. # axes3d = Axes3D(f)
  18. # axes3d.plot_surface(xgrid, ygrid, z)
  19. Axes3D(plt.figure()).plot_surface(xgrid, ygrid, z, cmap="hot", rstride=10, cstride=10)
  20. plt.show()
  21. help(Axes3D(plt.figure()).plot_trisurf)
  22.  
  23. exit()
  24. plt.contourf(z, 12, cmap="hot")
  25. plt.contour(z, 12, colors="black")
  26.  
  27. plt.show()
  28.  
  29. exit()
  30. n = 20
  31. x = np.random.random_sample(n)
  32. print(x)
  33. plt.figure()
  34. random.seed(7)
  35. # colors = [(i / len(x), i % 2, 0) for i in range(len(x))]
  36. colors = [[random.random() for j in range(3)] for i in range(len(x))]
  37. # plt.pie(x, colors=colors)
  38. # plt.legend(colors)
  39. # plt.bar(x, x)
  40. plt.bar(range(n), x, width=1)
  41. plt.bar(range(n), -x, width=1, color=colors)
  42. plt.show()
  43. help(plt.bar)
  44.  
  45.  
  46. exit()
  47. x = np.linspace(0, 2)
  48. plt.figure()
  49. for i in range(4):
  50.     # plt.axes([0.25 * i, 0.25 * i, 0.25, 0.25])
  51.     plt.axes([(i % 2) * 0.5 + 0.1, (1 - i // 2) * 0.5 + 0.1, 0.3, 0.3])
  52.     # plt.axes([(i % 2) * 0.5, (1 - i // 2) * 0.5, 0.5, 0.5])
  53.     y = x ** i
  54.     plt.plot(x, y)
  55.     plt.plot([1, 1, 0], [0, 1, 1], "--r", linewidth=3)
  56.     plt.title("$y = x^" + str(i) + "$")
  57.     plt.xlabel("x")
  58.     plt.ylabel("y", verticalalignment="bottom")
  59.     plt.ylim(0, 8)
  60. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement