本文介绍了具有更改y值的Matplotlib热图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制一些数据以用于从两个表面之间进行的测量.系统中的z方向定义为垂直于曲面.问题是,沿着图的x轴,我正在改变两个曲面之间的分隔距离,这意味着对于每个切片,y轴的最小值/最大值都会发生变化.我通过呈现标准化的y轴来规避此问题,其中z_min是底面,z_max是顶面:

I'm trying to plot some data for a measurement taken from between two surfaces. The z-direction in the system is defined as normal to the surfaces. The problem is that along the x-axis of my plot I'm varying the separation distance between the two surfaces which means that for every slice, the min/max of the y-axis change. I've sort circumvented this by presenting a normalized y-axis where z_min is the bottom surface and z_max is the top surface:

但是,这种表示在某种程度上扭曲了数据.理想情况下,我想在y轴上显示到墙的实际距离,而只将系统范围之外的区域保留为白色.我(很糟糕)在这里概述了我的构想(当然,热图上的实际分布看起来应该有所不同):

However, this representation somewhat distorts the data. Ideally I would like to show the actual distance to the wall on the y-axis and just leave the areas outside of the system bounds white. I (poorly) sketched what I'm envisioning here (the actual distribution on the heatmap should look different, of course):

我可以很容易地将所需的内容绘制为3D散点图,如下所示:

I can pretty easily plot what I want as a 3D scatter plot like so:

我猜我将不得不炸毁MxN数组并通过插值来填充丢失的值,或者干脆将它们标记为NAN?但是然后我也不太确定如何为我的配色方案添加硬性限制,以使系统外部的所有内容变为白色.

I'm guessing I would have to blow up the MxN array and fill in missing values through interpolation or simply mark them as NAN? But then I'm also not quite sure how to add a hard cutoff to my color scheme to make everything outside of the system white.

推荐答案

您可以使用 pcolormesh 做到这一点,该方法将四边形的角视为争论点

You can do this with pcolormesh which takes the corners of quadrilaterals as the arguements

X, Y = np.meshgrid(np.linspace(0, 10, 100), np.linspace(0, 2*np.pi, 150),)
h = np.sin(Y)
Y *= np.linspace(.5, 1, 100)

fig, ax = plt.subplots(1, 1)
ax.pcolormesh(X, Y, h)

这篇关于具有更改y值的Matplotlib热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 05:01