开发者

Any way to get a figure from Python's matplotlib into Matlab?

开发者 https://www.devze.com 2023-03-18 22:47 出处:网络
I\'m processing some data for a research project, and I\'m writing all my scripts in python. I\'ve been using matplotlib to create graphs to present to my supervisor. However, he is a die-hard MATLAB

I'm processing some data for a research project, and I'm writing all my scripts in python. I've been using matplotlib to create graphs to present to my supervisor. However, he is a die-hard MATLAB user and he wants me to send him MATLAB .fig files rather than SVG images.

I've looked all over but can't find anything to do the job. Is there any way to either export .fig fil开发者_高级运维es from matplotlib, convert .svg files to .fig, or import .svg files into MATLAB?


Without access to (or experience with matlab) this is going to be a bit tricky. As Amro stated, .fig files store the underlying data, and not just an image, and you're going to have a hard time saving .fig files from python. There are however a couple of things which might work in your favour, these are:

  • numpy/scipy can read and write matlab .mat files
  • the matplotlib plotting commands are very similar to/ based on the matlab ones, so the code to generate plots from the data is going to be nearly identical (modulo round/square brackets and 0/1 based indexing).

My approach would be to write your data out as .mat files, and then just put your plotting commands in a script and give that to your supervisor - with any luck it shouldn't be too hard for him to recreate the plots based on that information.

If you had access to Matlab to test/debug, I'm sure it would be possible to create some code which automagically created .mat files and a matlab .m file which would recreate the figures.

There's a neat list of matlab/scipy equivalent commands on the scipy web site.

good luck!

0

精彩评论

暂无评论...
验证码 换一张
取 消