• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

笔记|matplotlib |pcolormesh 函数着色规则

武飞扬头像
长行
帮助1

pcolormesh 的官方文档:https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.pcolormesh.html

pcolormesh 着色规则的官方文档:https://matplotlib.org/stable/gallery/images_contours_and_fields/pcolormesh_grids.html

matplotlib.axes.Axes.pcolormesh 函数和 matplotlib.axes.Axes.pcolor 函数均有 shading 参数可以用于网格的布局和网格点之间的着色。如果令 Z 表示颜色,XY 表示网格,那么如果 Z 的形状为 m × n m \times n m×n,则 XY 的 shape 可以是 ( m 1 ) × ( n 1 ) (m 1)\times(n 1) (m 1)×(n 1) m × n m \times n m×n,具体取决于 shading 参数的选择。

>>> from matplotlib import pyplot as plt
... import numpy as np
... np.random.seed(0)

构造测试数据如下:

>>> n_rows = 3
... n_cols = 5
... x = np.arange(n_cols   1)
... y = np.arange(n_rows   1)
... Z = np.random.randint(0, 3, (n_rows, n_cols))
>>> Z
[[0 1 0 1 1]
 [2 0 2 0 0]
 [0 2 1 2 2]]

shading = Flat

>>> fig, ax = plt.subplots()
... ax.pcolormesh(x, y, Z, shading="flat", vmin=np.min(Z), vmax=np.max(Z))
... X, Y = np.meshgrid(x, y)
... ax.plot(X.flat, Y.flat, "o", color="m")
... ax.set_xlim(-0.5, 5.5)
... ax.set_ylim(-0.5, 3.5)
... ax.set_title("shading=flat")

学新通

shading = nearest

>>> fig, ax = plt.subplots()
... ax.pcolormesh(x[:-1], y[:-1], Z, shading="nearest", vmin=np.min(Z), vmax=np.max(Z))
... X, Y = np.meshgrid(x, y)
... ax.plot(X.flat, Y.flat, "o", color="m")
... ax.set_xlim(-0.5, 5.5)
... ax.set_ylim(-0.5, 3.5)
... ax.set_title("shading=nearest")

学新通

shading = gouraud

fig, ax = plt.subplots()
ax.pcolormesh(x[:-1], y[:-1], Z, shading="gouraud", vmin=np.min(Z), vmax=np.max(Z))
X, Y = np.meshgrid(x, y)
ax.plot(X.flat, Y.flat, "o", color="m")
ax.set_xlim(-0.5, 5.5)
ax.set_ylim(-0.5, 3.5)
ax.set_title("shading=gouraud")

学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgafgjk
系列文章
更多 icon
同类精品
更多 icon
继续加载