我的图是Matplotlib3用Python3.7制作的。
我将数据处理成三维坐标系中的曲面。但是我发现我的表面在网格后面。我希望表面可以覆盖网格。我不知道如何解决。
我的代码:
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
# from IRCA import *
## Global Setting
plt.rc("font", **{"size":14,"family":"serif","serif":["Computer Modern"]})
plt.rc("text", usetex = True)
plt.rcParams["grid.color"] = "#D4D4D4"
plt.rcParams["grid.linestyle"] = "dashed"
formatter = mpl.ticker.ScalarFormatter(useMathText = True)
formatter.set_scientific(True)
formatter.set_powerlimits((-1,1))
## Plot Statement
fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")
## Title
fig.suptitle(r"SupTitle with \LaTeX", size=18, color="black")
ax.set_title(r"SubTitle with \LaTeX", size=16, color="black")
## Data Input
x, y, z = np.loadtxt("Data/dataTot.dat", unpack=True)
surf = ax.plot_trisurf(x, y, z, cmap="gnuplot")
## Ticks and Axes
ax.xaxis._axinfo["tick"]["inward_factor"] = 0.0
ax.xaxis._axinfo["tick"]["outward_factor"] = 0.2
ax.yaxis._axinfo["tick"]["inward_factor"] = 0.0
ax.yaxis._axinfo["tick"]["outward_factor"] = 0.2
ax.zaxis._axinfo["tick"]["inward_factor"] = 0.0
ax.zaxis._axinfo["tick"]["outward_factor"] = 0.2
ax.xaxis.pane.set_edgecolor("#D0D0D0")
ax.yaxis.pane.set_edgecolor("#D0D0D0")
ax.zaxis.pane.set_edgecolor("#D0D0D0")
ax.xaxis.pane.set_alpha(1)
ax.yaxis.pane.set_alpha(1)
ax.zaxis.pane.set_alpha(1)
ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
ax.invert_xaxis()
ax.invert_yaxis()
ax.invert_zaxis()
ax.set_proj_type("persp") # "ortho": Orthographic; "persp": Perspective(default)
ax.grid(True)
ax.set_axis_on()
## Figure Output
# fig.savefig("Python Matplotlib 3D.pdf", dpi=1080)
plt.show()
然后,文件:dataTot.dat是: https://github.com/ConAntares/Algorithms/blob/master/Data/dataTot.dat
答案 0 :(得分:2)
在绘制表面时使用antialiased=False
。阅读this答案以获得更好的解释。
surf = ax.plot_trisurf(x, y, z, cmap="gnuplot", antialiased=False)