python - 为什么我的等高线图的一部分显示为白色?

标签 python matplotlib contourf

我正在使用 Python 的 matplotlib.pyplot.contourf用颜色条创建我的数据的等高线图。我已经无数次成功地做到了这一点,即使使用相同变量的其他层也是如此。但是,当这些值变小时(大约为 1E-12),部分轮廓显示为白色。白色也不会出现在颜色栏中。有谁知道这是什么原因以及如何解决这个问题?错误的轮廓附在下面。

Bad contour

a1 = plt.contourf(np.linspace(1,24,24),np.linspace(1,20,20),np.transpose(data[:,:,15]))
plt.colorbar(a1)
plt.show()

最佳答案

tl;博士
鉴于新信息,matplotlib 无法为您的数据设置正确的级别数(文档中的 see parameters),而未绘制数据。要解决此问题,您需要告诉 matplotlib 使用 plt.contourf(..., extend="max") 扩展限制或 plt.contourf(..., extend="both") enter image description here
广泛的回答
有几个原因contourf()显示带有 colormap that doesn't include white 的白色区域.
NaN 值
从不绘制 NaN 值。
enter image description here
屏蔽数据
如果在绘图前屏蔽数据,它不会出现在绘图中。但是你应该知道你是否屏蔽了你的数据。
enter image description here
虽然,如果您使用类似 Tick locator 的东西,您可能会被忽视而掩盖您的数据。 = 日志定位器()。
enter image description here
Matplotlib 无法为您的数据设置正确的级别
有时 matplotlib 没有设置正确的级别,从而使您的一些数据没有绘图。
enter image description here
要解决该问题,您可以使用 plt.contourf(..., extend=EXTENDS)其中 EXTENDS 可以是 "neither", "both", "min", "max" enter image description here
粗网格
contourf plots whitespace over finite data. Past answers do not correct

关于python - 为什么我的等高线图的一部分显示为白色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61514157/

相关文章:

python - 氢包原子编辑器 - 奇怪的显示

python - 关闭顶级 Tkinter 窗口

python - 在 basemap 上绘图 - 意外结果

python - Python中的一个图形中的多个绘图

python - 为什么等高线图中的数据点之间没有线?

python - Django 。动态编写通知并正确呈现它们

python - matplotlib savefig - 文本被截断

python - contourf() 在有限数据上绘制空白区域

python - matplotlib:将颜色分配给半径

python - np.concatenate 的内存错误