{"id":2437,"date":"2009-07-02T12:56:41","date_gmt":"2009-07-02T12:56:41","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2009\/07\/02\/linkzoom\/"},"modified":"2022-05-29T20:15:39","modified_gmt":"2022-05-30T00:15:39","slug":"linkzoom","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2009\/07\/02\/linkzoom\/","title":{"rendered":"linkzoom"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/5021\">Bob<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/21414-linkzoom-m-v1-3--aug-2009-\">linkzoom<\/a> by Carlos Adrian Vargas Aguilera.\r\n      <\/p>\r\n   <\/introduction>\r\n   <p>The following plot shows temperature versus depth in two sets of units.<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">Z = linspace(0,150)';           <span style=\"color: #228B22\">% Depth in meters<\/span>\r\nTC = -tanh((Z-30)\/20)+23;       <span style=\"color: #228B22\">% Temperature in &deg;C<\/span>\r\ndc2df = @(dc) (9\/5)*dc + 32;    <span style=\"color: #228B22\">% &deg;C-&gt;&deg;F<\/span>\r\nmt2ft = @(mt) mt\/0.3048;        <span style=\"color: #228B22\">% meters-&gt;feet<\/span>\r\n\r\nax(1) = axes(<span style=\"color: #A020F0\">'YDir'<\/span>,<span style=\"color: #A020F0\">'reverse'<\/span>,<span style=\"color: #0000FF\">...<\/span>\r\n             <span style=\"color: #A020F0\">'Box'<\/span>,<span style=\"color: #A020F0\">'off'<\/span>,<span style=\"color: #0000FF\">...<\/span>\r\n             <span style=\"color: #A020F0\">'position'<\/span>,[0.13 0.11 0.77 0.78]);\r\nline(TC,Z,<span style=\"color: #A020F0\">'parent'<\/span>,ax(1))\r\naxis <span style=\"color: #A020F0\">tight<\/span>\r\nxlabel(<span style=\"color: #A020F0\">'Temperature, &deg;C'<\/span>)\r\nylabel(<span style=\"color: #A020F0\">'Depth, m'<\/span>)\r\nax(2) = axes(<span style=\"color: #A020F0\">'Position'<\/span>,get(ax(1),<span style=\"color: #A020F0\">'position'<\/span>),<span style=\"color: #0000FF\">...<\/span>\r\n             <span style=\"color: #A020F0\">'HitTest'<\/span>,<span style=\"color: #A020F0\">'off'<\/span>,<span style=\"color: #0000FF\">...<\/span>\r\n             <span style=\"color: #A020F0\">'XAxisLocation'<\/span>,<span style=\"color: #A020F0\">'top'<\/span>,<span style=\"color: #0000FF\">...<\/span>\r\n             <span style=\"color: #A020F0\">'YAxisLocation'<\/span>,<span style=\"color: #A020F0\">'right'<\/span>,<span style=\"color: #0000FF\">...<\/span>\r\n             <span style=\"color: #A020F0\">'YDir'<\/span>,<span style=\"color: #A020F0\">'reverse'<\/span>,<span style=\"color: #0000FF\">...<\/span>\r\n             <span style=\"color: #A020F0\">'XLim'<\/span>,dc2df(get(ax(1),<span style=\"color: #A020F0\">'XLim'<\/span>)),<span style=\"color: #0000FF\">...<\/span>\r\n             <span style=\"color: #A020F0\">'YLim'<\/span>,mt2ft(get(ax(1),<span style=\"color: #A020F0\">'YLim'<\/span>)),<span style=\"color: #0000FF\">...<\/span>\r\n             <span style=\"color: #A020F0\">'Color'<\/span>,<span style=\"color: #A020F0\">'none'<\/span>);\r\nxlabel(ax(2),<span style=\"color: #A020F0\">'Temperature, &deg;F'<\/span>)\r\nylabel(ax(2),<span style=\"color: #A020F0\">'Depth, ft'<\/span>)\r\nlinkzoom(ax)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/pick_linkzoom_01.png\"> <p>The different units of measure are handled using a second axes. If you want to zoom and pan the plot, by default the two axes\r\n      would not stay synchronized. MATLAB offers a very useful <tt><a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009a\/techdoc\/ref\/linkaxes.html\">linkaxes<\/a><\/tt> command. That works great when plots share common X and\/or Y coordinate values. In this case <tt>linkaxes<\/tt> would do the wrong thing. So Carlos created <tt>linkzoom<\/tt>. Once turned on, you can pan and zoom and both measurement scales stay in lock step. Download the submission and run this\r\n      code in MATLAB to see for yourself.\r\n   <\/p>\r\n   <p><\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_4424561c3ca44ff0ad1e9eee1d3439ab() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='4424561c3ca44ff0ad1e9eee1d3439ab ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 4424561c3ca44ff0ad1e9eee1d3439ab';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Robert Bemis';\r\n        copyright = 'Copyright 2009 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_4424561c3ca44ff0ad1e9eee1d3439ab()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.9<br><\/p>\r\n<\/div>\r\n<!--\r\n4424561c3ca44ff0ad1e9eee1d3439ab ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/5021 Bob>'s \r\n% pick this week is \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/21414-linkzoom-m-v1-3--aug-2009- linkzoom> \r\n% by Carlos Adrian Vargas Aguilera.\r\n%%\r\n% The following plot shows temperature versus depth in two sets of units.\r\nZ = linspace(0,150)';           % Depth in meters\r\nTC = -tanh((Z-30)\/20)+23;       % Temperature in \u00c2\u00b0C\r\ndc2df = @(dc) (9\/5)*dc + 32;    % \u00c2\u00b0C->\u00c2\u00b0F\r\nmt2ft = @(mt) mt\/0.3048;        % meters->feet\r\n\r\nax(1) = axes('YDir','reverse',...\r\n             'Box','off',...\r\n             'position',[0.13 0.11 0.77 0.78]);\r\nline(TC,Z,'parent',ax(1))\r\naxis tight\r\nxlabel('Temperature, \u00c2\u00b0C')\r\nylabel('Depth, m')\r\nax(2) = axes('Position',get(ax(1),'position'),...\r\n             'HitTest','off',...\r\n             'XAxisLocation','top',...\r\n             'YAxisLocation','right',...\r\n             'YDir','reverse',...\r\n             'XLim',dc2df(get(ax(1),'XLim')),...\r\n             'YLim',mt2ft(get(ax(1),'YLim')),...\r\n             'Color','none');\r\nxlabel(ax(2),'Temperature, \u00c2\u00b0F')\r\nylabel(ax(2),'Depth, ft')\r\nlinkzoom(ax)\r\n%%\r\n% The different units of measure are handled using a second axes. If you want\r\n% to zoom and pan the plot, by default the two axes would not stay\r\n% synchronized. MATLAB offers a very useful \r\n% |<https:\/\/www.mathworks.com\/help\/releases\/R2009a\/techdoc\/ref\/linkaxes.html linkaxes>| \r\n% command. That works great when plots share common X and\/or Y coordinate\r\n% values. In this case |linkaxes| would do the wrong thing. So Carlos created\r\n% |linkzoom|. Once turned on, you can pan and zoom and both measurement\r\n% scales stay in lock step. Download the submission and run this code in\r\n% MATLAB to see for yourself.\r\n%%\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p2437#respond Comments?>\r\n\r\n##### SOURCE END ##### 4424561c3ca44ff0ad1e9eee1d3439ab\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n      Bob's pick this week is linkzoom by Carlos Adrian Vargas Aguilera.\r\n      \r\n   \r\n   The following plot shows temperature versus depth in two sets of units.Z = linspace(0,150)';    ... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2009\/07\/02\/linkzoom\/\">read more >><\/a><\/p>","protected":false},"author":46,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2437"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/46"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2437"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2437\/revisions"}],"predecessor-version":[{"id":15971,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2437\/revisions\/15971"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}