Two figures have different sizes when plotted using contourf and colorbar

Hello,
I am using contourf to plot two different figures. Below is sample code which runs using the .mat file attached.
clear all; close all; clc;
load contourfproblemdata.mat;
figure1 = figure('Position',[400 300 300 300]);
contourf(X,Y,data1,50,'linestyle','none'); axis equal; hold all;
colormap gray; xlim([-100 100]); ylim([-100 100]);
colorbar;
figure2 = figure('Position',[400 300 300 300]);
contourf(X,Y,data2,50,'linestyle','none'); axis equal; hold all;
colormap gray; xlim([-100 100]); ylim([-100 100]);
colorbar;
If you flip back and forth between figure1 and figure2, you'll see that the plots shift slightly, and that the colorbar on figure2 is partially obscured (the black border is somewhat missing from the left side of the colorbar).
Any help would be much appreciated!
Thanks, Kristin

 Accepted Answer

Even when I enlarge the figure boxes, I don’t see the shift, or the problem with the colorbar.
My machine: HP laptop, Win 8 64, latest videodrivers, MATLAB R2014a.

3 Comments

My pleasure! Anything for a fellow 'Hoo!
The figures in ‘test_officecomputer.pdf’ are obviously different, but when I pull up all the others in different tabs (Firefox), they all display the same. I can’t tell any difference in size.
Unfortunately, I have absolutely no recent experience in LaTeX, so I can’t help you with that.
I can’t reproduce your error, so unfortunately, I can’t experiment with a fix for it. However, since you’re printing your figures, there are some options in Figure Properties you might explore, particularly PaperOrientation, PaperPosition, PaperPositionMode, PaperType, and PaperUnits. I can’t guarantee that those will fix the problem, but if you haven’t already experimented with them, I suggest them as possibilities.
I’m sure you’ve looked through the documentation on print by now, and have specified the appropriate printer drivers as well.
You might want to be sure you have all the latest MATLAB updates. As bugs are reported, fixes are published and it’s possible to download free updates.
I’ll do what I can to help. I have the advantage of trying them on a different computer.
ADDENDUM — I was surfing the File Exchange and re-discovered export_fig. You might also experiment with it to see if it solves your problem.
I've done some more investigating, and when I open my .eps files in Notepad, I can see that the %%BoundingBox dimensions were different for my two figures. From: this google group thread I've tried using the following to print my figures:
print(figure1,'-depsc','-loose','test1.eps');
print(figure2,'-depsc','-loose','test2.eps');
and this results in two .eps files with identical boundingbox dimensions. They now also appear as the same size in my LaTeX document.
Thank you for your help!
PS - I have tried using export_fig, but have failed miserably at installing pdftops from http://www.foolabs.com/xpdf. Do you have experience with using this function?
Thanks again! Kristin
My pleasure!
I’m glad the -loose option worked for you. I haven’t done anything with Postscript or Ghostscript in a while, so I forgot they existed.
I haven’t had any need for a PDF-to-Postscript converter, so I haven’t had any experience with pdftops. According to the Xpdf description, it apparently needs to be compiled to use it.
I just now did a brief search (on DuckDuckGo) for ‘pdf to postscript converter windows’ and came up with several hits. You might want to do a similar search to see if one of them would work for you.
I use PDF-XChange for everything related to PDFs. MATLAB creates decent PDFs, and I can view and manipulate them with PDF_XChange easily. It doesn’t convert PDFs to Postscript, though.
Have fun with your research!

Sign in to comment.

More Answers (1)

Thanks for trying out my code. The machine I have the problem on is running Matlab R2013b on Windows 7 64-bit.
Where the problem really occurs is that I'm trying to use these figures in LaTeX and I'm required to use *.eps format. So, I'm printing the figures to .eps via:
print(figure1,'-depsc','officetest1.eps');
print(figure2,'-depsc','officetest2.eps');
and also, out of curiosity, to .jpgs using:
saveas(figure1,'officetest1.jpg');
saveas(figure2,'officetest2.jpg');
Then, when I go to use them in my LaTeX code:
\documentclass[12pt]{article}
\usepackage{graphicx}
\graphicspath {{my graphics path..}}
\begin{document}
\begin{figure} [H]
\centering
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=1\linewidth]{officetest1.eps}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=1\linewidth]{officetest2.eps}
\end{minipage}
\end{figure}
\end{document}
Their size difference is very noticeable, as seen in the attached pdf "test_officecomputer.pdf". The shift is evident (to me, on my office computer) in the officetest.jps's as well.
I've also tried using a virtual computing network available to us which runs Matlab R2013a. I run the same Matlab code (except name the files "virtual..." instead of 'office"). Running this way, the .jps no longer have the shift and look great (looking at them on both my office and virtual machines). However, when I email myself the .eps files to include them in a LaTeX document, they are better, but still different sizes in the .pdf.
Do you see a difference in the figures I've attached? I feel like I'm going crazy...
Thanks again for your help, Kristin

Categories

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!