matplotlib 中的 pcolor
我在 matplotlib 中使用 pcolor。我使用三维数组作为输入。我想安排第三个数组以对数刻度显示。有没有办法做到这一点?如果我在绘制第三个数组之前对其取对数,则子值将变为负值,并且 pcolor 不再起作用。
I am using pcolor in matplotlib. I use a three dimensional array as the input. I want to arrange the third array to be displayed in a log scale. Is there an option to do this? If I take a logarithm of the third array before plotting it, the sub one values become negative and pcolor no longer works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设你的第三个维度的数据都是正数(因为负数的对数未定义),那么使用 pcolor 绘制它应该不会有任何问题(注意:Matplotlib 文档建议使用
pcolormesh
而不是pcolor
)。此时,我将提请注意帖子的编辑历史记录,其中显示“sub one”过去常说“subzero”,这会产生 NaN;我稍后会解决这个问题。正如当前版本所说,小于 1(且大于 0)的数字的对数为负数。您提到使用 pcolor 绘制负数时遇到问题,但这不会影响任何内容。假设正数,下面的代码应该可以工作。
如果我们考虑原始文本,则使用
np.log
表示负数将产生NaN
,如前所述。将我们的Z
定义切换为Z = X**2 - Y + 0.1
,我们会收到警告。这仍然会生成一个绘图,但不会绘制数据为 NaN 的位置。
版本
:
Assuming the data of your third dimension are all positive (since the log of a negative number is undefined), then you should not have any issues plotting this using
pcolor
(note: the Matplotlib documentation recommendspcolormesh
rather thanpcolor
). At this point, I'll call attention to the post's edit history which shows that "sub one" used to say "subzero", which would produceNaN
s; I will address this later. As the current version says, the logarithm of a number less than 1 (and greater than 0) is negative. You mention having an issue plotting negative numbers usingpcolor
, but that should not affect anything.Assuming positive numbers, the code below should work.
If we take instead consider the original text, using
np.log
for the negative numbers will produceNaN
s, as mentioned earlier. Switching ourZ
definition toZ = X**2 - Y + 0.1
, we will get a warning.This will still produce a plot, but the locations where the data are
NaN
will not be plotted.Versions: