对于具有自定义级别的 matplotlib 轮廓图,颜色图被忽略

发布于 2025-01-06 01:00:31 字数 517 浏览 2 评论 0原文

我正在尝试在 matplotlib (Win7,1.1.0)中创建填充轮廓图。我想突出显示某些值,并且级别更接近对数而不是线性。

有许多颜色图适合我,但我选择的 cmap 被忽略了。

我需要创建自定义“标准化”吗?如果是这样,每个轮廓是否根据其边缘值着色,然后用相同的颜色填充到下一个较低的值?为什么这个症状会忽略我的颜色图......这是施工过程中的一些异常被捕获并且我的请求被默默地忽略吗?

我的原始数据有缺失值。我尝试过制作这个纳米,大的和小的......在每种情况下,我都尝试掩盖它们而不是掩盖“外部”值。我还使用默认级别和规范尝试了所有排列。

lev = [0.1,0.2,0.5,1.0,2.0,4.0,8.0,16.0,32.0]
norml = colors.normalize(0,32)
cs = plt.contourf(x,z,data,cmap=cm.gray, levels=lev, norm = norml)

我希望这个片段至少足以开始对话。

谢谢, 伊莱

I am trying to create a filled contour plot in matplotlib (Win7, 1.1.0). I want to highlight certain values, and the levels are closer to log than linear.

There are numerous colormaps that would suit me, but my choice of cmap is ignored.

Do I need to create a custom "normalize"? If so is each contour colored according to its edge value and then filled with the same color to the next lower value? Why is the symptom of this to ignore my color map ... is this some exception during construction that is being caught and my request is being silently ignored?

My original data had missing values. I have played with making thise nan, large and small ... in each case I have tried masking them and not masking the "outside" values. I have also tried all permutations using the default levels and norm.

lev = [0.1,0.2,0.5,1.0,2.0,4.0,8.0,16.0,32.0]
norml = colors.normalize(0,32)
cs = plt.contourf(x,z,data,cmap=cm.gray, levels=lev, norm = norml)

I hope this snippet is sufficient to at least start the conversation.

Thanks,
Eli

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒路情人 2025-01-13 01:00:31

如果我理解正确,您需要使用级别作为基础而不是默认的线性缩放来将数据重新缩放为颜色。如果这是正确的,那么您需要使用 colors.BoundaryNorm作为标准因子。考虑以下示例:

x = np.arange(0,8,0.1)
y = np.arange(0,8,0.1)
z = (x[:,None]-4) ** 2 + (y[None,:]-4) ** 2

lev = [0.1,0.2,0.5,1.0,2.0,4.0,8.0,16.0,32.0]
norml = colors.BoundaryNorm(lev, 256)
cs = plt.contourf(x, y, z, cmap = cm.jet, levels = lev, norm = norml)
plt.show()

这会产生

在此处输入图像描述

将其与默认Normalize 行为进行比较:

< img src="https://i.sstatic.net/BOo2k.png" alt="在此处输入图像描述">

希望有所帮助。

If I understood you correctly, you need to rescale your data to colors using your levels as the basis rather than default linear scaling. If that's right, then you need to use colors.BoundaryNorm as the norm factor. Consider the following example:

x = np.arange(0,8,0.1)
y = np.arange(0,8,0.1)
z = (x[:,None]-4) ** 2 + (y[None,:]-4) ** 2

lev = [0.1,0.2,0.5,1.0,2.0,4.0,8.0,16.0,32.0]
norml = colors.BoundaryNorm(lev, 256)
cs = plt.contourf(x, y, z, cmap = cm.jet, levels = lev, norm = norml)
plt.show()

This yields

enter image description here

Compare it to default Normalize behaviour:

enter image description here

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文