python - 方点等高线图

标签 python plot matplotlib

我有 3 个数据集,X、Y、Z,它们分别是我的轴和我的数据。它们定义明确,即 len(X) = len(Y) = len(Z) = len(Z[i]) = N for i in range(0,N).

我想制作一个类似于 contourf 图(我已经制作了),但是使用离散轴,就像“等高线方 block ”一样,其中每个方 block (x,y) 都有一个Z 值(浮点值)给出的颜色。

到目前为止,我使用的是 contourf(X,Y,Z),但它进行了一些我不想要的插值,我需要使用正方形进行更好的可视化。

有人知道怎么做吗?

谢谢

最佳答案

您应该使用 ma​​tshowimshow 绘图函数。

这里的一个重要参数是插值。 检查这个example from the matplotlib gallery查看一些示例。

通过使用 matshow(),关键字参数被传递给 imshow()matshow()origininterpolation(='nearest')和aspect<设置默认值/em>.

这是我自己工作中的一个例子...

# level, time and conc are previously read from a file

X,Y=[level,time]   
Z=conc.transpose() # Create the data to be plotted

cax = matshow(Z, origin='lower', vmin=0, vmax=500)
    # I am telling all the Z values above 500 will have the same color
    # in the plot (if vmin or vmax are not given, they are taken from
    # the input’s minimum and maximum value respectively)
grid(True)
cbar = colorbar(cax)

...返回此图:

perfil vertical

关于python - 方点等高线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9579217/

相关文章:

python - 使用深度学习防止多类分类中的特定类过度拟合

r - 向三角形中心弯曲线(ggplot2)

python - Python 中的 GPU 加速数据绘图

python - 合并缺少 x 值的图

python - 你如何制作 numpy 数组的 ggplot 图?

python - 如何使用python从列表Json中获取数据

python - 错误 : Cannot uninstall requests 2. 25.1,未找到记录文件。提示:该软件包是通过 rpm 安装的

python - Python 列表理解中的平等

python - 带有单个子图的 Matplotlib

python - Pandas 随时间绘制计数器的累计总和