matplotlib三维等高线标签

2024-04-20 10:21:02 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有办法把等高线标签放在三维绘图中?Clabel显然没有在3D中实现

import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

x,y = np.meshgrid(np.linspace(-1,1,10),np.linspace(-1,1,10))
z=-(x**2+y**2)

fig,ax = plt.subplots()
C=ax.contour(x,y,z)
ax.clabel(C)

fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')
C=ax.contour(x,y,z,zdir='z',offset=-2)
ax.clabel(C)

enter image description hereenter image description here


Tags: importnumpy绘图asnpfigplt标签