contourf参数 python_matplotlib.pyplot可视化库中contour与contourf的区别

本文介绍了Python Matplotlib库中contour和contourf两个函数的区别,前者绘制非填充的等高线,后者则填充等高线区域。通过示例代码展示了如何使用这两个函数,并结合cmap调整颜色,以及如何添加颜色条。
摘要由CSDN通过智能技术生成

contour做的云图不是填充的,而contourf画的云图是填充的

来两个例子一目了然,代码可用。(本文例子来自matplotlib管网)

contour函数

contour([X, Y,] Z, [levels], **kwargs)

X, Y, The coordinates of the values in Z.

X and Y must both be 2-D with the same shape as Z (e.g. created via numpy.meshgrid), or they must both be 1-D such that len(X) == M is the number of columns in Z and len(Y) == N is the number of rows in Z.

If not given, they are assumed to be integer indices, i.e. X = range(M), Y = range(N).

Z array-like(N, M)

The height values over which the contour is drawn.

levels int or array-like, optional

Determines the number and positions of the contour lines / regions.

If an int n, use MaxNLocator, which tries to automatically choose no more than n+1 “nice” contour levels between vmin and vmax.

If array-like, draw contour lines at the specified levels. The values must be in increasing order.

import matplotlib

import numpy as np

import matplotlib.cm as cm

import matplotlib.pyplot as plt

delta = 0.025

x = np.arange(-3.0, 3.0, delta)

y = np.arange(-2.0, 2.0, delta)

X, Y = np.meshgrid(x, y)

Z1 = np.exp(-X**2 - Y**2)

Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)

Z = (Z1 - Z2) * 2

fig, ax = plt.subplots()

CS = ax.contour(X, Y, Z)

ax.clabel(CS, inline=True, fontsize=10)

ax.set_title('Simplest default with labels')<

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值