Mon 5 Dec 2005
in working with trasect figures in Matlab7.1 (R14) on my mac over the past few days, i have discovered a few secrets:
- Matlab has a canned feature for plotting with two Y-axis vairables (plotyy.m), but leaves double X-axis plotting up to the user. the way to do this is to create one figure, and then overlay a second set of axes on top of the original by ‘get’ting the axes ‘Position’ from the original set and using that to set the ‘Position’ for the second. when creating dual x-axis figures, there are a few things to consider:
1. overlapping tickmarks - if you create two sets of axes, it is likely because you are trying to plot two seperate sets of variables with different scales. This means dual tick-marks which may make your figure overly confusing. Possible solutions:
- use set(gca,’TickDir’,'out’) on one axes set to differentiate from the inward tick marks.
- do not use tick marks (see the next ’secret’ for more info)
- turn the bounding box off to remove ticks from secondary x and y axes, while leaving the primary tickmarks. set(gca,’Box’,'off’)
2. overlapping axes - only certain visualization fuctions seem to be compatible with xx figures. for example, adding a bar or plot is not possible as far as i can tell, nor are multiple levels to one of the axes (ie. no ‘hold on’ allowed!). much trial and error seems necessary! note: put more complicated figure (ie. contour, pcolor) on the bottom layer.
3. remember to turn off the background color in the overlapped axes, the default is white which will obscure the original figure. set(gca,’Color’,'none’)
4. set the second x-axis to the top by using the ‘XAxisLocation’ setting ‘top’.
- tick marks are fun! there are a few things the books don’t tell you:
1. while you CAN have tickmarks without labels, you CANNOT label intervals without tickmarks! you can get around this by hint #2.
2. you can change the tick mark length! this hidden value is not in any book or help menu that i have found, but it is invaluable for removing tick marks but leaving the labels. i found it using the ‘inspector’ feature under the plot tools. the command is set(gca,’TickLength’,[a b]) where a and b are mystery values. my experimentation shows that a must be a positive value greater than zero (ie. 0.001), or the tick marks will not appear at all, and that b seems linked to the actual length, with 0.4 being a common starting value, 5 being very very long! using [0 0.01] will remove the ticks from the figure. using this command in combination with ‘Box’,'off’ will leave the tick marks on your screen-display figure looking seperated from the axis, but when you export this problem disappears in the .tif version.
3. another way to include labels without the tick marks is to use the text function which still works well in double axes.
- the matlab defaults for image quality are very poor. suggestions are as follows:
1. when exporting, create a .tif with the openGL renderer and 150dpi. this will give a full-page figure of around 2Mb that looks nice. 300dpi is nicer, but the file size starts to get out of hand.
2. printing from the screen figure works well, but for some reason the pageSetup options are greyed out on the printMenu. remember to set your pageSetup Lines and Axes to ‘Color’ before printing!
- i have not yet found a way to make the colorbar logrithmic. i belive this is possible by changing the axes defaults for the colorbar (set bar=colorbar to get the handle for the axes!) but i do not know if it will translate the axes change to the color values. another possibility is to create a new colormap with log intervals for color. i will post more when i have it figured out!
One Response to “matlab visualization tips”
Leave a Reply
You must be logged in to post a comment.


December 5th, 2005 at 4:50 pm
Hi Lynn,
Thanks for the post. FYI, I removed the category “Blog” since this is implied by the category hierarchy. Additionally, I added the categories “Tools” and “Hints” to this post.