matplotlib中的等高线contour之clabel用法

本文介绍如何使用matplotlib绘制等高线图,并详细解释了如何利用clabel函数为等高线添加标签,使图表更加易读。通过具体代码示例展示了从数据准备到图表展示的全过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

365JHWZGo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值