Matplotlib-在同一轴上绘制两个3D曲面时重叠错误 [英] Matplotlib - Wrong overlapping when plotting two 3D surfaces on the same axes

查看:75
本文介绍了Matplotlib-在同一轴上绘制两个3D曲面时重叠错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用plot_surface命令在matplotlib中的同一轴上绘制两个3D曲面.

I am trying to plot two 3D surfaces on the same axes in matplotlib with the plot_surface command.

fig = plt.figure()
fig.figsize = fig_size
ax = fig.gca(projection='3d')

surf = ax.plot_surface(X, Y, Exp_Fric_map, alpha = 1, rstride=1, cstride=1, cmap=cm.winter, linewidth=0.5, antialiased=True)
surf = ax.plot_surface(X, Y, Fric_map, alpha = 1, rstride=1, cstride=1, cmap=cm.autumn,linewidth=0.5, antialiased=True)

我遇到的问题是,在查看绘图时,并非总是正确的表面位于顶部",例如在绘图中:

The problem I have is that when viewing the plot, not always the correct surface is 'on top', for instance in the plot:

在后角(200N,轴上为2.5Hz)中,当黄红色实际上更靠近观察者时,蓝绿色表面在顶部".如果我旋转情节:

in the back corner (200N, 2.5Hz on the axes) the blue-green surface is 'on top' when actually the yellow-red is closer to the viewer. If I rotate the plot:

然后一切正常,蓝绿色表面在200N和2.5Hz的黄红色表面之下(现在在左侧).我曾尝试搜索stackoverflow和Google,但找不到任何类似的解决方案问题.

then things look ok now, the blue-green surface is underneath the yellow-red one at 200N and 2.5Hz (now on the left side). I have tried searching stackoverflow and Google but cannot find any similar problems with a solution.

我在Linux上使用的是Python 2.7.3,Numpy 1.6.1和Matplotlib 1.1.1rc.

I am using Python 2.7.3, Numpy 1.6.1 and Matplotlib 1.1.1rc on Linux.

推荐答案

就像画画一样.哪一个位于最上方"取决于您最后绘制哪一个.

It's just like painting. which one is 'on top' is determined by which one you draw at last.

您可能想使用 zorder 属性告诉matplotlib应该以何种顺序绘制表面.

You might want to use zorder property to tell matplotlib in what order the surfaces should be painted.

例如:

ax.plot_surface(X, Y, Exp_Fric_map, alpha = 1, rstride=1, cstride=1, cmap=cm.winter, linewidth=0.5, antialiased=True, zorder = 0.5)
ax.plot_surface(X, Y, Fric_map, alpha = 1, rstride=1, cstride=1, cmap=cm.autumn,linewidth=0.5, antialiased=True, zorder = 0.3)


更新:

我已经进行了一些测试,我相信这是matplotlib的 bug ,它在单个图形中绘制了多个表面.例如,它制作了一些3D世界中不应该存在的表面,例如:

I have run a couple of tests and I believe it is a bug of matplotlib while painting multiple surfaces in a single figure. For example, it made some surfaces that should not exist in our 3D-world like:

,尝试后我看不到有效的解决方案.正如我说的,因果关系是绘画的顺序: matplotlib总是一一画画.如果某个表面的一部分应该在顶部,而另一部分应该在底部,则matplotlib会出错.

, and I can see no effective solution after trying. The causation is the order of painting, as I said: matplotlib always paints things one by one. if a part of a surface should be on top, and another part of it should be on bottom, matplotlib will go wrong.

因此,我的建议是停止解决这个问题,除非您想为matplotlib做出贡献,否则这是浪费时间.如果您必须解决此问题,我建议您去寻找另一个绘图工具以完成您的工作.

Therefore my suggestion would be that stop tackle this problem, it's a waste of time unless you want to contribute to matplotlib. If this is mandatory for you to solve, I would suggest that just go to find another plotting tool to finish your job.

这篇关于Matplotlib-在同一轴上绘制两个3D曲面时重叠错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆