2

My figure was made by Matplotlib3 with Python3.7.

I processed my data into a surface in a three-dimensional coordinate frame. But I found that my surface is behind the grid. I hope that the surface can cover the grid. I don't know how to fix it.

Surface

My Code:

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()

Then, the file: dataTot.dat is: https://github.com/ConAntares/Algorithms/blob/master/Data/dataTot.dat

Luke Niu
  • 141
  • 7
  • 1
    I'm not sure it's behind the grid. Maybe you can change the transparency settings of the surface you are plotting with the `alpha` kwarg like in [this](https://stackoverflow.com/questions/4320021/matplotlib-transparent-line-plots) question – C.Nivs Apr 29 '19 at 17:02

1 Answers1

2

Use antialiased=False while plotting the surface. Read this answer for a better explanation.

surf = ax.plot_trisurf(x, y, z, cmap="gnuplot", antialiased=False)

enter image description here

Sheldore
  • 37,862
  • 7
  • 57
  • 71