One think I do a lot in Matlab is make plots that I want to export to
some other program (I'm currently using Matlab 7.0.0.19920 under Windows
XP). Ideally, I want these plots to look the same whether I print them
from Matlab or from whatever program I paste them into. Usually, I'm
pasting into either Adobe Illustrator or Microsoft Word.
I find that this is harder than it should be. If I do the obvious
thing, and select Edit/Copy Figure from the figure menu bar, I find that
the figures look pretty bad when pasted into, say, Word. If I print
them from Word, they look kind of like what I would get if I printed
them direct from Matlab, but plotted curves are generally jaggier, and
there seem to often be minor glitches with the way the tics and tic
labels are drawn. If I try to paste figures into Illustrator (I'm using
version 10.0.3), I get the error "Can't paste the objects. The
requested transformation would make some objects fall completely off the
drawing area." This, obviously, is unsatisfying. (Perhaps the problem
lies with Illustrator, but I can paste metafiles from other applications
into Illustrator.)
Under the Matlab preferences, the Figure Copy Template settings are all
set to the defaults, and the Figure Copy Template/Copy Options are set
as follows: Clipboard format is set to "Preserve information (metafile
if possible)", Figure background color is set to "Transparent
background", and under Size:, "Match figure screen size" is checked.
I've tried using the "Bitmap" setting for the Clipboard format, but the
resolution seems to be quite low (maybe 100 dpi or so), and this just
isn't adequate for my needs.
To work around the above issues, I usually save figures as .eps files.
If I want to import to Illustrator, I can then just open the .eps files
(this works very nicely). If I want to import to Word, I usually render
the .eps file using Ghostscript to a 300 dpi image (using antialiasing),
and then insert the image using Insert/Picture. This also works nicely.
I know that I could insert the .eps file directly, but with the above
method I get to see a high-res version of the figure when I look at the
document in Word.
The problem with all of this is that I export figures from Matlab _a
lot_, and all of the methods above are either low quality (cutting and
pasting) or slow (outputing to a file, possibly rendering to an image,
opening the file in the target application). Is there a way to do
cut-and-paste which gives high-quality results? Partly I'm asking
because it seems like I must be missing something obvious. It seems
like what I'm doing (exporting figures) must be pretty common, and so
there must be a good, fast way to do it.
Thanks for any help you can give,
Adam
--
Adam L. Taylor
altaylor at brandeis dot edu
in our case this yields fig qualities that are indistinguishable from
generic ML output (i realize that you already implement some of it).
i suggest you try this once more
1) open a word doc
2) ML
peaks(64);
axis square;
% the <-rxxx> flag is important!
print -dmeta -r300; % or higher (ram!)
3) back in word
edit
-> paste special
-> picture (enhanced metafile)
this should yield a very nice, ie non-jagged pic.
just a thought
us
try:
save as -> adobe illustrator file (*.ai)
HTH,
Chandresh
I'm trying to get a plot with a number of contour sections on it and
a colour bar, into Illustrator, but for some reason, when you export
it as an ai file, the colour bar is lost (or at least the colours -
the outline remains, but this kinda defeats the object really). The
colours within the contour plots are not true to the original either.
Sometimes I can get a result if I export as an eps file and then open
this in Illustrator, but not this time. I get the colourbar, but the
colours within the contour sections are lost. Perhaps there is just
too much data for Illustrator to cope with?
The best result is a .tif file opened in Photoshop, but now I'm stuck
as to how to get this into Illustrator, again without losing the
quality.
In fact I have just posted a question about this at the end of a
thread that was started to help me create the contour plots in the
first place!
If I get a response, I shall post it here also.
In Matlab 6.5.0.196271, what you suggested works nicely. I didn't
realize that 'print -dmeta' copied to the clipboard. Foolish of me,
because there it is in the documentation!
I guess my only other complaint is that I can't set the copy options to
make -r300 (or whatever) the default when I do a copy via Ctrl-C. This
is unfortunate. Does anyone know if there's any way to do _that_?
Also, in Matlab 7.0.0.19920, if I try what you suggest (more or less), I
get:
>> figure;
>> peaks(64);
z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ...
- 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ...
- 1/3*exp(-(x+1).^2 - y.^2)
>> print -dmeta -r300
Warning: Failed in BitBlt, device does not support this operation
(gle00000008)
> In graphics\private\render at 100
In print at 261
>>
Hmmm. Hopefully this will be fixed soon in version 7.
Thanks again,
Adam
-----
Do you have a code snippet that produces the problematic figure? Also,
what version of Matlab are you using, on what OS? Without knowing
anything else, I'd suggest changing the Renderer property of the figure
to 'Painters' (if it isn't already), and then trying to export again.
You are exporting as a Color EPS, right? Are you exporting as 'EPS
Color' or 'EPS Level 2 Color'? I would think that 'EPS Level 2 Color'
would be more likely to work.
I tried using 'print -dill' once upon a time, and didn't get very good
results. On the other hand, I've _always_ gotten good results by using
'print -epsc2' and then opening the resulting file in Illustrator. (I
think doing File/Export... and selecting 'EPS Level 2 Color' is
essentially the same thing.) My only complaint is that this is not as
fast as doing Ctrl-C, switching to Illustrator, and doing Ctrl-V.
On that note, have you tried 'print -dmeta -r600' and then doing a paste
in Illustrator?
Adam
-----
Sarah wrote:
this function will resave all matlab figures in a directory as
full-page TIFF images with the same name. I work with images using
transparency, hence the OpenGL renderer. I agree EPS would probably
be the way to go for your purposes, so the following function can be
modified accordingly. "help print" for a hint as to how this
modification can be made. I have never lost colorbars, tick labels
or axes labels with this function. Mind the line breaks from
posting... hopefully they are obvious.
function fig2tiff
figs = dir('*.fig');
fignames = {figs.name};
for i=1:length(fignames)
open(char(fignames(i)));
set(gcf,'Renderer','OpenGL','PaperOrientation','landscape',...
'PaperPosition',[0.2500 0.3617 10.5000 7.7766],
'inverthardcopy','off');
set(gca, 'XTickMode','manual', 'YTickMode','manual',
'ZTickMode','manual');
print ('-r150', '-dtiffn', fignames{i}(1:length(fignames{i})-4));
close
end
print -dmeta -r300
Warning: Failed in BitBlt, device does not support this operation
(gle00000008)
In graphics\private\render at 100
In print at 261
> Hmmm. Hopefully this will be fixed soon in version 7.
my bet: it is your gpu-driver - and not a bug in ML.
here, r14 runs the sequence without complaining...
did you upgrade to the latest?
just a thought
us
> Adam Taylor:
> <SNIP eternal conundrum of how to import ML figs into other apps
> (especially word)...
>
This is an eternal conundrum, and its amazed me that this hasn't been
fixed.
To compare it to SigmaPlot, a publication quality graphic package that I've
been using since it's DOS days--
Since SigmaPlot moved to Windows about 10 years ago, I've been able to cut
from the sigmaplot window, and paste into absolutely every application I've
ever tried it with-- word, excel, powerpoint, photoshop, coreldraw, and the
list goes on. I've never had any problems doing so-- the white backgrounds
don't print "fuzzy" (I've never understood this), the graphics appear
exactly as they did in sigmaplot (whether I simply paste or paste special
as graphics), it prints on every printer I try it with.
More to the point-- I have complete confidence that this is the way
sigmaplot works. I don't have to hold my breath and hope that a $40
printout of a poster comes out the way it should.
A plea to the steering committee-- can you get this on the dream list??
I'd love to be able to cut and paste with impunity, as I do with all my
other applications.
Scott
cheering <sigma plot>...
scott, i second you with every (sic!) single measly axon of my rather
deteriorated nervous system - and - as you very well know, we use SP
here in our labs.
however, did you ever find a great way of importing a complex, ML
generated graph into SP?
best
urs
> Scott Seidman:
> <SNIP eternal conundrum of how to import ML figs into other apps
> (especially word)...
>
> cheering <sigma plot>...
>
> scott, i second you with every (sic!) single measly axon of my rather
> deteriorated nervous system - and - as you very well know, we use SP
> here in our labs.
I've had my moments with those guys. In particular, I seem to remember
their second Windows release was buggy as hell, and actually had a nifty
way of shredding data! The version I use now seems marginally stable.
Also, SigmaPlot is becoming bloatware, and is very expensive if all you
want to do is make pretty pictures!. I've tried Kaleidagraph recently, but
don't like the way it manages data. I've actually been trying to use
Matlab more and more for graphics, but this export problem makes me grimace
every time I think about publishing (which doesn't happen often enough!)
SigmaPlot's interesting from the business end, too. Jandel started the
whole thing, then sold to SPSS (who also managed to buy SYSTAT, which I
love), then SPSS sold Systat to Systat, Inc, and now Systat Inc bought
SigmaPlot in the last coupla months. Now, there's a new release of Systat,
and I think theres a new release of SigmaPlot coming out. I don't have the
warm fuzzies about either one of those apps, to tell you the truth
Many thanks <us> for this sample code. I have accepted a
"Matlab-problem" for years. Now it seems to be gone.
I make scatter plots with tens of thousands of points. I include them
in Word using File|Copy Figure and in Word Edit|Paste
Special|Enhanced meta format. Those files I convert to pdf using
Acrobat Distiller.
The apperance is no problem, but scrolling the Word file is a pain
and downloading the pdf-file over the Internet is even more painful.
From now on I will use <print -dmeta -r300>. They hardly delay
scrolling of the Word file.
How come? I just don't understand. The two procedures obviously
creates very different EMF-files. Should I find myself a book on
graphical fileformats and their use in Windows? Any recommendadion.
/ per
> however, did you ever find a great way of importing a complex, ML
> generated graph into SP?
> best
> urs
>
>
oops-- hit send too soon
Once upon a time, at Neuroscience, I met a Jandel guy who emailed me some
utilities to use SigmaPlot with Matlab. I never tried them--I don't
remember which way they moved data and/or graphics, but I do know they
existed once upon a time. I've been poking about my files but haven't had
any luck.
When I need to mix graphs from a variety of apps, I tend to rely on
Powerpoint, Photoshop, or the like as a central point
Scott
Why do you think this is a problem with the graphics card driver? I
wouldn't think outputing to a metafile (a vector format) would exercise
the graphics card at all.
Adam
-----
I agree with you, it does seem like a pretty lame state of affairs. I
was half-hoping my post would elicit some responses like yours, and that
this would in turn prompt someone at The Mathworks to a) explain why
this state of affairs persists, and b) generate some enthusiasm within
the company for remedying it. I mean, it's not as if cut-and-paste is a
new thing. And I get the impression that a good fraction of Matlab
users use Matlab on Windows (anyone have a number on this?).
What seems especially frustrating is that Matlab seems to incorporate
the functionality to copy a figure to the clipboard as an enhanced
metafile, just not as easily as one would like. 'print -dmeta -r1200'
seems to do the job quite nicely (as least on the figures I've tried it
on). I get the impression that doing 'Copy Figure' with the copy
options set to 'metafile' basically does something like 'print -dmeta'.
But according to the docs, the default resolution for this is the
screen resolution. But since it's a metafile (a vector format), doing
it at a higher resolution adds very little to the file size (I checked).
So why not make the default resolution for 'print -dmeta' (and for
Copy Figure) something like, say, 1200 dpi? This seems like it would
give much more satifying results in the majority of cases. But maybe
there's some complication in all this that I'm missing...
And of course, if one wanted to get somewhat more fancy, it would be
nice if the copy options allowed you to specify a default resolution.
Or perhaps one default resolution for metafiles and one for bitmaps
(while I'm asking...).
Adam
-----
Scott Seidman wrote:
--
> Should I find myself a book on graphical fileformats and their use
in Windows?
nahhh - per! don't waste your time with such second order problems.
we need you for better than such petty chores, eg., continue to
produce very good code on TMWs fex.
us
adam, it works properly with this and a few other nvidia/wintel
configs
p4/2.26g/512m/xp.sp2/r14/geforce4mx440/driver:07/12/04-6.1.7.6/word200
2/10.5815.4219.sp2
> Why do you think this is a problem with the graphics card driver?
...just believe me (?!). :-)
us
>
>How come? I just don't understand. The two procedures obviously
>creates very different EMF-files. Should I find myself a book on
>graphical fileformats and their use in Windows? Any recommendadion.
>
>/ per
Actually the 'Save As...' menu widget (if you go into the dropdown
list) allows you to save a matlab figure as an .emf (enhanced
metafile), so there's a third way...
Matt Feinstein
--
There is no virtue in believing something that can be proved to be true.
I hope you got the figure I e-mailed you that I am having problems
with. I have tried all your suggestions but with mixed success.
1) Illustrator will not open an EPS Level 2 Color file.
2) 'Painters' exports the black lines (i.e. images and points plotted
using plot3), but ignores the contours, which I have created using
surf and interp.
3) 'OpenGL' exports the contours beautifully, but not the black
lines.
I thought I would try one of each and mix and match the two figures
in Illustrator. Time consuming, but if it gets me the image on my
poster... Unfortunately, however, the .eps image is saved as strips
of information rather than individual points or lines as usual. This
means that I cannot select just the contour sections to cut and paste
into the second .eps image.
I have tried all sorts of combinations, but cannot find one that
carries over both,
"area plots (bar graphs, histograms, etc.), and simple surface plots"
(Help ref. for Painter)
and
"for complex surface plots using interpolated shading and any figure
using lighting" (Help ref. for OpenGL)
If anyone has any more ideas I would be very grateful to read them
but as it is, I have had to discard the figure I have created and go
back to a series of 2D plots instead.
> So why not make the default resolution for 'print -dmeta' (and for
Copy Figure) something like, say, 1200 dpi?
i fully agree with you. TMW should make the <-r> an option.
now, since def vals are kept in
matlabroot/matlab/graphics/printjob.m
a quick-and-dirty workaround could be:
- backup the file
- change the entry
pj.DPI = -1;
- to
pj.DPI = 1200;
which, of course, will affect other formats as well.
just a pedestrian thought
us
Huh. I tried the same thing on another machine in the lab, running
Matlab 7 on Windows 2000, and it worked fine, as you say.
So I uninstalled R14, installed XP SP2, installed R14 again, and tried
it again, and it still failed.
To try to figure out what what might be going on w/ my Nvidia driver, I did:
>> feature('usegenericopengl',1)
>> opengl info
Version = 1.1.0
Vendor = Microsoft Corporation
Renderer = GDI Generic
MaxTextureSize = 1024
Visual = 23 (RGB 32 bits(08 08 08 00) zdepth 32, Generic,
Opengl, Double Buffered, Window)
Extensions = GL_WIN_swap_hint GL_EXT_bgra GL_EXT_paletted_texture
Hardware Bug Workarounds:
OpenGLBitmapZbufferBug = 1
OpenGLWobbleTesselatorBug = 0
OpenGLDockingBug = 0
>> figure; peaks(64)
>> print -dmeta -r300
Warning: Failed in SetDIBits, device does not support this operation
(gle00000008)
> In graphics\private\render at 100
In print at 261
>>
So it fails even if I don't use the Nvidia driver. (At least I don't
think I'm using it...).
_Very strangely_, if I do:
>> print -dmeta -r237
That works, although the resulting metafile is very big, and so goes
outside the bounding box.
But if I do the following, it fails, as you can see:
>> print -dmeta -r238
Warning: Failed in BitBlt, device does not support this operation
(gle00000008)
> In graphics\private\render at 100
In print at 261
Strange...
Adam
> >> figure; peaks(64)
> >> print -dmeta -r300
> Warning: Failed in SetDIBits, device does not support this
> operation
> (gle00000008)
> > In graphics\private\render at 100
> In print at 261
hmmm, what gpu/driver version do you use?
us