Python绘制五颜六色反转等高线图

import numpy as np
import matplotlib.pyplot as plt

origin = 'lower'

delta = 0.025

x = y = np.arange(-3.0, 3.01, 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

nr, nc = Z.shape

# put NaNs in one corner:
Z[-nr // 6:, -nc // 6:] = np.nan
# contourf will convert these to masked


Z = np.ma.array(Z)
# mask another corner:
Z[:nr // 6, :nc // 6] = np.ma.masked

# mask a circle in the middle:
interior = np.sqrt(X**2 + Y**2) < 0.5
Z[interior] = np.ma.masked
fig1, ax2 = plt.subplots(layout='constrained')
CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.bone, origin=origin)

# Note that in the following, we explicitly pass in a subset of the contour
# levels used for the filled contours.  Alternatively, we could pass in
# additional levels to provide extra resolution, or leave out the *levels*
# keyword argument to use all of the original levels.

CS2 = ax2.contour(CS, levels=CS.levels[::2], colors='r', origin=origin)

ax2.set_title('Nonsense (3 masked regions)')
ax2.set_xlabel('word length anomaly')
ax2.set_ylabel('sentence length anomaly')

# Make a colorbar for the ContourSet returned by the contourf call.
cbar = fig1.colorbar(CS)
cbar.ax.set_ylabel('verbosity coefficient')
# Add the contour line levels to the colorbar
cbar.add_lines(CS2)
plt.show()

在这里插入图片描述

CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.Accent, origin=origin)

在这里插入图片描述

CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.Accent_r, origin=origin)

在这里插入图片描述

CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.Blues, origin=origin)

在这里插入图片描述

CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.Blues_r, origin=origin)

在这里插入图片描述

CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.BrBG, origin=origin)

在这里插入图片描述

CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.BrBG_r, origin=origin)

在这里插入图片描述

CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.BuGn, origin=origin)

在这里插入图片描述

CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.BuGn_r, origin=origin)

在这里插入图片描述

CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.BuPu, origin=origin)

在这里插入图片描述

CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.BuPu_r, origin=origin)

在这里插入图片描述

CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.CMRmap, origin=origin)

在这里插入图片描述
参考文献:https://matplotlib.org/stable/gallery/images_contours_and_fields/contourf_demo.html#sphx-glr-gallery-images-contours-and-fields-contourf-demo-py
开发工具:Visual Studio 2022和微信Alt+A截屏工具

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值