如何删除表面图上的正方形?

huangapple go评论96阅读模式
英文:

How can I remove the squares on a surface plot

问题

I have a matplotlib code to plot a certain 3d function.

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. L = 10
  4. a = 0.4
  5. type = "COS"
  6. fig = plt.figure(figsize=(12, 10))
  7. ax = plt.axes(projection='3d')
  8. ax.grid(False)
  9. ax.set_xticks([])
  10. ax.set_yticks([])
  11. ax.set_zticks([])
  12. x = np.arange(0, L, 0.05)
  13. y = np.arange(0, 20, 0.05)
  14. X, Y = np.meshgrid(x, y)
  15. def f(x, t, n):
  16. return np.cos(n * np.pi * x / L) * np.exp(-a * n * n * np.pi * np.pi * a * t / (L * L))
  17. def s(n):
  18. if type == "PAR":
  19. if n > 0:
  20. return L * L * (4 * np.pi * n + 4 * np.pi * n * ((-1) ** n)) / (2 * (np.pi ** 3) * (n ** 3))
  21. else:
  22. return L * L / 12
  23. elif type == "COS":
  24. if n > 0:
  25. return 2 * (L * np.sin(L) * ((-1) ** n)) / (L * L - np.pi * np.pi * n * n)
  26. else:
  27. return np.sin(L) / L
  28. def g(x, t):
  29. ans = s(0)
  30. for n in range(1, 200):
  31. ans += s(n) * f(x, t, n)
  32. return ans
  33. Z = g(X, Y)
  34. surf = ax.plot_surface(X, Y, Z, cmap=plt.cm.inferno)
  35. ax.set_xlabel('x', labelpad=20)
  36. ax.set_ylabel('t', labelpad=20)
  37. ax.set_zlabel('T', labelpad=20)
  38. plt.show()

But, when I go to plot this, I get this:

如何删除表面图上的正方形?

As you can see, the plotted surface has rectangles on it, and I don't want them. How can I remove them? I tried removing grids and axis but that doesn't affect anything.

英文:

I have a matplotlib code to plot a certain 3d function.

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. L = 10
  4. a = 0.4
  5. type = "COS"
  6. fig = plt.figure(figsize = (12,10))
  7. ax = plt.axes(projection='3d')
  8. ax.grid(False)
  9. ax.set_xticks([])
  10. ax.set_yticks([])
  11. ax.set_zticks([])
  12. x = np.arange(0, L, 0.05)
  13. y = np.arange(0, 20, 0.05)
  14. X, Y = np.meshgrid(x, y)
  15. def f(x,t,n):
  16. return np.cos(n*np.pi*x/L)*np.exp(-a*n*n*np.pi*np.pi*a*t/(L*L))
  17. def s(n):
  18. if type == "PAR":
  19. if n > 0:
  20. return L*L*(4*np.pi*n+4*np.pi*n*((-1)**n))/(2*(np.pi**3)*(n**3))
  21. else:
  22. return L*L/12
  23. elif type == "COS":
  24. if n > 0:
  25. return 2*(L*np.sin(L)*((-1)**n))/(L*L-np.pi*np.pi*n*n)
  26. else:
  27. return np.sin(L)/L
  28. def g(x,t):
  29. ans = s(0)
  30. for n in range(1,200):
  31. ans += s(n)*f(x,t,n)
  32. return ans
  33. Z = g(X,Y)
  34. surf = ax.plot_surface(X, Y, Z, cmap = plt.cm.inferno)
  35. ax.set_xlabel('x', labelpad=20)
  36. ax.set_ylabel('t', labelpad=20)
  37. ax.set_zlabel('T', labelpad=20)
  38. plt.show()

But, when I go to plot this, I get this:
如何删除表面图上的正方形?

As you can see, the plotted surface has rectangles on it, and I don't want them. How can I remove them? I tried removing grids and axis but that doesn't affect anything.

答案1

得分: 1

你可以使用 antialiased=False

  1. surf = ax.plot_surface(X, Y, Z, cmap=plt.cm.inferno, antialiased=False)
英文:

You can use antialiased=False:

  1. surf = ax.plot_surface(X, Y, Z, cmap=plt.cm.inferno, antialiased=False)

如何删除表面图上的正方形?

huangapple
  • 本文由 发表于 2023年5月11日 15:53:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76225282.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定