matplotlib中的等高线contour之clabel用法:
用法:
plt.clabel()
参数:
CS【ContourSet instance】
Line contours to label.
inline【bool, default: True】
If True the underlying contour is removed where the label is placed.
fontsize【default: 10.0】
fontsize
举例:
'''
Author: 365JHWZGo
Description: matplotlib--Contours
Date: 2021/11/1 14:32
FilePath: day1101-1.py
'''
# 导包
import numpy as np
import matplotlib.pyplot as plt
# 创造数据
x = np.linspace(-3, 3, 256) # x
y = np.linspace(-3, 3, 256) # y
# 高
def H(x, y):
return (1 - x / 2 + x ** 5 + y ** 3) * np.exp(-x ** 2-y ** 2)
X, Y = np.meshgrid(x, y) #生成网格点
#print(X)
#print(Y)
plt.contourf(X,Y,H(X,Y),8,alpha=.75,cmap=plt.cm.hot)
C = plt.contour(X,Y,H(X,Y),8,color='black',linewidth=.5)
plt.clabel(C,inline=True,fontsize=10)
plt.xticks(())
plt.yticks(())
plt.show()