在同一个图中结合 mayavi 和 matplotlib [英] Combining mayavi and matplotlib in the same figure

查看:60
本文介绍了在同一个图中结合 mayavi 和 matplotlib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会制作动画.在每一帧中,我想同时包含一个用

I will be making animations. In each frame I want to contain both a mayavi plot obtained with

mlab.pipeline.iso_surface(source, some other superfluous args)

和使用简单

pylab.plot(args)

我有单独的脚本,但不知道如何将它们组合成一个图形.我希望最终产品是一个脚本,其中包含我目前拥有的两个脚本的代码.

I have scripts to do both separately, but have no idea how to go about combining them into one figure. I want the end product to be one script which contains the code from both the scripts that I currently have.

推荐答案

AFAIK,没有直接的方法,因为使用的后端是如此不同.似乎不可能将 matplotlib 轴添加到 mayavi.figure,反之亦然.

AFAIK, there is no direct way because the backends used are so different. It does not seem possible to add matplotlib axes to mayavi.figure or vice versa.

但是,使用mlab.screenshot 有一种方式".

However, there is a "kind of a way" by using the the mlab.screenshot.

import mayavi.mlab as mlab
import matplotlib.pyplot as plt

# create and capture a mlab object
mlab.test_plot3d()
img = mlab.screenshot()
mlab.close()

# create a pyplot
fig = plt.figure()
ax1 = fig.add_subplot(121)
ax1.plot([0,1], [1,0], 'r')

# add the screen capture
ax2 = fig.add_subplot(122)
ax2.imshow(img)
ax2.set_axis_off()

这不一定是最好的做事方式,您也可能会遇到分辨率问题(检查 mayavi 窗口的大小).但是,它在大多数情况下都能完成工作.

This is not necessarily the nicest possible way of doing things, and you may bump into resolution problems, as well (check the size of the mayavi window). However, it gets the job done in most cases.

这篇关于在同一个图中结合 mayavi 和 matplotlib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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