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

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

How can I remove the squares on a surface plot

问题

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

import numpy as np
import matplotlib.pyplot as plt
L = 10
a = 0.4
type = "COS"
fig = plt.figure(figsize=(12, 10))
ax = plt.axes(projection='3d')
ax.grid(False)
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])

x = np.arange(0, L, 0.05)
y = np.arange(0, 20, 0.05)

X, Y = np.meshgrid(x, y)
def f(x, t, n):
    return np.cos(n * np.pi * x / L) * np.exp(-a * n * n * np.pi * np.pi * a * t / (L * L))

def s(n):
    if type == "PAR":
        if n > 0:
            return L * L * (4 * np.pi * n + 4 * np.pi * n * ((-1) ** n)) / (2 * (np.pi ** 3) * (n ** 3))
        else:
            return L * L / 12
    elif type == "COS":
        if n > 0:
            return 2 * (L * np.sin(L) * ((-1) ** n)) / (L * L - np.pi * np.pi * n * n)
        else:
            return np.sin(L) / L

def g(x, t):
    ans = s(0)
    for n in range(1, 200):
        ans += s(n) * f(x, t, n)
    return ans

Z = g(X, Y)

surf = ax.plot_surface(X, Y, Z, cmap=plt.cm.inferno)
ax.set_xlabel('x', labelpad=20)
ax.set_ylabel('t', labelpad=20)
ax.set_zlabel('T', labelpad=20)
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.

import numpy as np
import matplotlib.pyplot as plt
L = 10
a = 0.4
type = "COS"
fig = plt.figure(figsize = (12,10))
ax = plt.axes(projection='3d')
ax.grid(False)
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])

x = np.arange(0, L, 0.05)
y = np.arange(0, 20, 0.05)

X, Y = np.meshgrid(x, y)
def f(x,t,n):
    return np.cos(n*np.pi*x/L)*np.exp(-a*n*n*np.pi*np.pi*a*t/(L*L))


def s(n):
    if type == "PAR":
        if n > 0:
            return L*L*(4*np.pi*n+4*np.pi*n*((-1)**n))/(2*(np.pi**3)*(n**3))
        else:
            return L*L/12
    elif type == "COS":
        if n > 0:
            return 2*(L*np.sin(L)*((-1)**n))/(L*L-np.pi*np.pi*n*n)
        else:
            return np.sin(L)/L


def g(x,t):
    ans = s(0)
    for n in range(1,200):
        ans += s(n)*f(x,t,n)
    return ans


Z = g(X,Y)

surf = ax.plot_surface(X, Y, Z, cmap = plt.cm.inferno)
ax.set_xlabel('x', labelpad=20)
ax.set_ylabel('t', labelpad=20)
ax.set_zlabel('T', labelpad=20)
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

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

You can use antialiased=False:

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:

确定