简体   繁体   中英

matplotlib contours labels in 3D

Is there any way to put contours labels in 3D plots? Clabel is apparently not implemented in 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)

在此处输入图片说明 在此处输入图片说明

As clabel is not implemented and the return value is None, there is indeed no point in calling clabel() for the time being. You can use the C.levels attribute to manually add labels to the graph .

It won't have the nice inline feature that hides the contour under the labels though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM