CINXE.COM

User guide for plotlys matlab® library in MATLAB

<!DOCTYPE html> <html> <head> <!-- This page was last built at 2024-11-19 16:02 --> <meta charset="utf-8" /> <link rel="canonical" href="https://plotly.com/matlab/user-guide/" /> <link rel="preconnect" href="https://fonts.googleapis.com" /> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> <link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@1,500&display=swap" rel="stylesheet" /> <!-- Media query magic - http://stackoverflow.com/questions/19945658/my-iphone-thinks-its-980px-wide --> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <script src="/all_static/javascripts/algolia/instantsearch.js"></script> <script src="/all_static/javascripts/algolia/polyfill.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> <script> const theme = localStorage.getItem('theme'); if (theme === "dark-mode") { var root = document.getElementsByTagName('html')[0]; // '0' to assign the first (and only `HTML` tag) root.setAttribute('class', 'dark-mode'); } </script> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" crossorigin="anonymous"> <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" crossorigin="anonymous"></script> <link href="https://esm.sh/@markprompt/css@0.18.0?css" rel="stylesheet" /> <link href="/all_static/css/markprompt.css" rel="stylesheet" /> <!-- code highlighting --> <!-- <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.8.0/highlight.min.js"></script> <script> hljs.initHighlightingOnLoad(); </script>--> <!-- Mathjax --> <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"></script> <!-- Plotly.js --> <script src="https://cdn.plot.ly/plotly-2.35.2.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.2/require.js"></script> <script type="text/javascript"> if (typeof require !== "undefined") { require.undef("plotly"); requirejs.config({ paths: { plotly: [ "https://cdn.plot.ly/plotly-2.35.2.min", ], }, }); require(["plotly"], function(Plotly) { window._Plotly = Plotly; }); } </script> <!-- //// Stylesheets --> <style> .mcode { border: 1px solid #cfcfcf; border-radius: 2px; background: #f7f7f7; padding: 10px; } </style> <!-- Fonts --> <link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic,800,800italic|Ubuntu+Mono:400,700|Asap" rel="stylesheet" type="text/css" /> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" /> <!-- Main Stylesheets --> <link rel="stylesheet" type="text/css" href="/all_static/css/main.css?version=false" /> <link rel="stylesheet" type="text/css" href="/all_static/css/improve.css?version=2024-11-19-16-02"> <!-- LOCAL DEV STYLESHEET --> <!--<link rel="stylesheet" type="text/css" href="http://api.plotly.dev/all_static/css/main.css">--> <!-- Icon --> <link rel="shortcut icon" href="https://dash.plotly.com/assets/favicon.ico" /> <!-- Google Tags--> <!-- Google Tag Manager Tag --> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-N6T2RXG');</script> <!-- META TAGS --> <!-- Capture language --> <!-- Create a title --> <!-- Count number of plots on the page --> <!-- SEO Tags - title, meta_description --> <title> User guide for plotlys matlab<sup>&reg;</sup> library in MATLAB </title> <meta name="description" content=How to use the core functions of Plotlys Matlab Open Source Graphing Library> <!-- Bing tags --> <meta name="msvalidate.01" content="D319859A832F9F1D15A7646E2A42150A" /> <!-- Facebook tags --> <meta property="og:title" content= User guide for plotlys matlab<sup>&reg;</sup> library in MATLAB /> <meta property="og:type" content="website"/> <meta property="og:image" content="https://images.plot.ly/plotly-documentation//images/static-image"> <meta property="og:description" content=How to use the core functions of Plotlys Matlab Open Source Graphing Library/> <meta property="og:url" /> <meta property="fb:admins" content="1123751525"/> <meta property="fb:admins" content="22418"/> <!-- twitter tags --> <meta name="twitter:card" content="photo" /> <meta name="twitter:title" content= User guide for plotlys matlab<sup>&reg;</sup> library in MATLAB /> <meta name="twitter:url" content="https://plotly.com/matlab/user-guide/"/> <meta name="twitter:description" content=How to use the core functions of Plotlys Matlab Open Source Graphing Library/> <meta name="twitter:image" content="https://images.plot.ly/plotly-documentation//images/static-image"> <meta name="twitter:site" content="@plotlygraphs"/> </head> <body data-spy="scroll" data-target=".watch" style="position:relative;" class="darkmode"> <!-- Google Tag Manager (noscript) --> <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-N6T2RXG" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> <!-- End Google Tag Manager (noscript) --> <!--[if lt IE 10]> <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> <![endif]--> <div class="menu-mobile"> <div class="switch-mode"> <div class="icon-dark"></div> <div class="switch"></div> <div class="icon-light"></div> </div> <div class="close-menu"></div> <ul> <li><a style="font-weight: bold;" href="https://community.plotly.com/c/plotly-r-matlab-julia-net/29">Forum</a> </li> <li><a style="font-weight: bold;" href="https://plotly.com/get-pricing/">Pricing</a></li> <li><a style="font-weight: bold;" href="https://dash.plotly.com">Dash</a></li> <!--<li><a style="font-weight: bold;" href="http://plotly.cloud">Dash Cloud</a></li>--> </ul> </div> <div class="header-container"> <header class="header-main --default"> <div class="--wrap"> <div class="--wrap-left"> <div class="-identity"> <a href="https://plotly.com/"><img src="/all_static/images/graphing_library_dark.svg" style="height: 30px;" class="logo-dark"></a> <a href="/graphing-libraries/"><img src="/all_static/images/graphing_library.svg" style="height: 30px;" class="logo-white"></a> </div> </div> <div class="--wrap-right"> <nav class="--nav-meta" role="navigation"> <ul> <li class="languages"> <a class="matlab"> <div class="icon"></div> MATLAB® </a> <ul> <li> <a href="https://plotly.com/python/" class="python"> <div class="icon"></div>Python (v5.24.1) </a> </li> <li> <a href="https://plotly.com/r/" class="r"> <div class="icon"></div>R </a> </li> <li> <a href="https://plotly.com/julia/" class="julia"> <div class="icon"></div>Julia </a> </li> <li> <a href="https://plotly.com/javascript/" class="plotly_js"> <div class="icon"></div>Javascript (v2.35.2) </a> </li> <li> <a href="https://plotly.com/ggplot2/" class="ggplot2"> <div class="icon"></div>ggplot2 </a> </li> <li> <a href="https://plotly.com/matlab/" class="matlab"> <div class="icon"></div>MATLAB </a> </li> <li> <a href="https://plotly.com/fsharp/" class="fsharp"> <div class="icon"></div>F# </a> </li> <li> <a href="https://dash.plotly.com/" class="dash"> <div class="icon"></div>Dash </a> </li> </ul> </li> <li><a style="font-weight: bold;" href="https://community.plotly.com/c/plotly-r-matlab-julia-net/29">Forum</a> </li> <li><a style="font-weight: bold;" href="https://plotly.com/get-pricing/">Pricing</a></li> <li><a style="font-weight: bold;" href="https://dash.plotly.com">Dash</a></li> <!--<li><a style="font-weight: bold;" href="http://plotly.cloud">Dash Cloud</a></li>--> <iframe src="https://ghbtns.com/github-btn.html?user=plotly&repo=plotly_matlab&type=star&count=true&size=large" style="padding-top: 5px;" frameborder="0" scrolling="0" width="160px" height="40px"></iframe> </ul> <div class="switch-mode"> <div class="icon-dark"></div> <div class="switch"></div> <div class="icon-light"></div> </div> </nav> </div> <div class="menu-icon"> <span></span><span></span><span></span> </div> </div> </header> </div> <main class="--page page--single --index"> <div class="--wrap"> <!-- aside - Main Sidebar--> <!-- START OF GGPLOT CUSTOM LAYOUT --> <aside class="--sidebar-container"> <div class="--sidebar-fixed reference" data-spy="affix" id="where"> <div class="brand"> <a href="/graphing-libraries/"><img src="/all_static/images/graphing_library.svg" style="height: 30px;"></a> </div> <details style="color: white;margin-top: 20px;" > <summary>Quick Reference</summary> <nav class="--sidebar-body watch" id="where"> <ul class="--sidebar-list" style="margin-left: 15px;"> <!-- Getting Started --> <li class="--sidebar-item"> <a href="/matlab/getting-started" class="js-splash--navigation-item">Getting Started</a> </li> <li class="--sidebar-item"> <a href="/matlab/is-plotly-free" class="js-splash--navigation-item">Is Plotly Free?</a> </li> <!-- Reference Pages --> <li class="--sidebar-item"> <a href="/matlab/reference/index/" class="js-splash--navigation-item">Figure Reference</a> </li> <!-- Python Specific --> <!-- JS Specific --> <!-- R Specific --> <!-- Python/v3 Index Page Specific --> <!-- User Guides --> <li class="--sidebar-item"> <a href="/matlab/user-guide/" class="js-splash--navigation-item">User Guide</a> </li> <!-- Github Links --> <li class="--sidebar-item"> <a target="_blank" href="https://github.com/plotly/plotly-graphing-library-for-matlab" class="js-splash--navigation-item">GitHub</a> </li> <li class="--sidebar-item"> <a target="_blank" href="http://community.plotly.com/" class="js-splash--navigation-item">community.plotly.com</a> </li> </ul> </nav> </details> <details style="color: white;margin-top: 20px;" open> <summary>On This Page</summary> <nav class="--sidebar-body watch" id="where"> <ul class="--sidebar-list" id="nav_header_insertion_list"></ul> </nav> </details> </div> <a href="https://go.plotly.com/dash-club?utm_source=Dash+Club+2022&utm_medium=graphing_libraries&utm_content=sidebar" target="_blank"> <img src="https://images.prismic.io/plotly-marketing-website-2/7953022d-73b1-481e-8f6b-9ce9bd80e588_Dash+Club.jpeg?auto=compress,format" style="width: 200px; height: 200px; position: fixed; bottom: 10px; left: 50px" alt="Sign up to Dash Club to get two free cheat sheets as well as tips and tricks, community apps, and deep dives delivered every two month"> </a> </aside> <!-- Main--> <section class="--page-body --tutorial-index --base"> <header class="--welcome"> <div class="--welcome-body"> <!--div.--wrap-inner--> <div class="--title"> <div class="--body"> <div class="nav-breadcrumb-container"> <div> <div class="breadcrumb-nav"> <a href="/matlab"> MATLAB<sup>&reg;</sup> </a> &gt; <span>User Guide for Plotlys MATLAB<sup>&reg;</sup> Library</span> </div> </div> <div class="nav-breadcrumb-right"> <div class="--fork"> <a id="forklink" href= "https://github.com/plotly/graphing-library-docs/edit/master/_posts/matlab/other_pages/2021-08-04-matlab-user-guide.html" > <div class="icon"> <svg style="width:20px;height:20px" viewbox="0 0 24 24"> <path fill="#000000" d="M2.6,10.59L8.38,4.8L10.07,6.5C9.83,7.35 10.22,8.28 11,8.73V14.27C10.4,14.61 10,15.26 10,16A2,2 0 0,0 12,18A2,2 0 0,0 14,16C14,15.26 13.6,14.61 13,14.27V9.41L15.07,11.5C15,11.65 15,11.82 15,12A2,2 0 0,0 17,14A2,2 0 0,0 19,12A2,2 0 0,0 17,10C16.82,10 16.65,10 16.5,10.07L13.93,7.5C14.19,6.57 13.71,5.55 12.78,5.16C12.35,5 11.9,4.96 11.5,5.07L9.8,3.38L10.59,2.6C11.37,1.81 12.63,1.81 13.41,2.6L21.4,10.59C22.19,11.37 22.19,12.63 21.4,13.41L13.41,21.4C12.63,22.19 11.37,22.19 10.59,21.4L2.6,13.41C1.81,12.63 1.81,11.37 2.6,10.59Z"> </path> </svg> </div> <span>Suggest an edit to this page</span> </a> </div> </div> </div> <h1> User Guide for Plotlys MATLAB<sup>&reg;</sup> Library in MATLAB<sup>&reg;</sup> </h1> <p>How to use the core functions of Plotlys Matlab Open Source Graphing Library </p> <br> <!-- <div class="db-client-lib"> <label> This page in another language </label> <div class="list-lib-wrap"> <div class="list-lib"> <a href=" /matlab/user-guide/" class="current list-lib-item matlab"> <div class="item-icon"> </div> <p class="item-language"> MATLAB® </p> </a> </div> </div> </div> --> </div> </div> </div> </header> <!-- Start Plotly Basics Section --> <section class="tutorial-content"> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> </div> <div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p><b>Plotly</b> is a browser-based data analysis and visualization tool that lets you and your team make and share beautiful, interactive graphs, 3D graphs, and streaming graphs via the open source JavaScript graphing library <a href="https://plotly.com/javascript/">plotly.js</a>. <br>This API allows MATLAB<sup>&reg;</sup> users to generate Plotly graphs from the desktop MATLAB<sup>&reg;</sup> environment: turning MATLAB<sup>&reg;</sup> figures into interactive, shareable, collaborative projects. <br>For more information on how to create specific chart types see our <a href="https://plotly.com/matlab/">documentation examples</a>.</p> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> </div> <div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <h4 id="Initial-Setup">Initial Setup<a class="anchor-link" href="#Initial-Setup">&#194;&#182;</a></h4><p>The Plotly Graphing Library for MATLAB<sup>&reg;</sup> has been embedded into our MATLAB<sup>&reg;</sup> toolboxes and our Plotly credentials have been saved using <code>plotlysetup.m</code>. In order to start using the Plotly Graphing Library for MATLAB<sup>&reg;</sup> API all we have to do now is start MATLAB! More information regarding installation / setting up the Plotly Graphing Library for MATLAB<sup>&reg;</sup> API can be found on the <a href="https://plotly.com/matlab/getting-started/">online documentation</a>.</p> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> </div> <div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <h4 id="How-It-Works">How It Works<a class="anchor-link" href="#How-It-Works">&#194;&#182;</a></h4><p>Plotly charts are described declaratively with struct and cell array objects. For an extensive list of the keys used to describe plotly graphs see <a href="https://plotly.com/matlab/reference/">our reference page</a>. To get an idea of how the MATLAB<sup>&reg;</sup> API works, check out this simple example of how to translate a MATLAB<sup>&reg;</sup> figure, modify some attributes, and then send it to Plotly.</p> </div> </div> </div> <div class="cell border-box-sizing code_cell rendered"> <div class="input"> <div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div> <div class="inner_cell"> <div class="input_area"> <div class=" highlight hl-ipython2"><pre><span></span><span class="o">&gt;&gt;</span> <span class="n">x</span> <span class="o">=</span> <span class="n">linspace</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="o">*</span><span class="n">pi</span><span class="p">,</span> <span class="mi">2</span><span class="o">*</span><span class="n">pi</span><span class="p">);</span> <span class="o">&gt;&gt;</span> <span class="n">y1</span> <span class="o">=</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">);</span> <span class="o">&gt;&gt;</span> <span class="n">y2</span> <span class="o">=</span> <span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">);</span> <span class="o">&gt;&gt;</span> <span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y1</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y2</span><span class="p">);</span> <span class="o">%%</span> <span class="n">Translate</span> <span class="n">the</span> <span class="n">figure</span> <span class="kn">from</span> <span class="nn">MATLAB</span> <span class="nn">to</span> <span class="nn">Plotly</span> <span class="o">&gt;&gt;</span> <span class="n">fig</span> <span class="o">=</span> <span class="n">plotlyfig</span><span class="p">(</span><span class="n">gcf</span><span class="p">);</span> <span class="o">&gt;&gt;</span> <span class="n">fig</span><span class="o">.</span><span class="n">PlotOptions</span><span class="o">.</span><span class="n">Strip</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="o">%</span> <span class="n">If</span> <span class="mi">0</span><span class="p">,</span> <span class="n">don</span><span class="s1">&#39;t strip MATLAB&#39;</span><span class="n">s</span> <span class="n">styling</span> <span class="ow">in</span> <span class="n">translation</span><span class="o">.</span> <span class="n">If</span> <span class="mi">1</span><span class="p">,</span> <span class="n">strip</span> <span class="n">MATLAB</span><span class="s1">&#39;s styling.</span> <span class="o">&gt;&gt;</span> <span class="n">fig</span><span class="o">.</span><span class="n">data</span> <span class="n">ans</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="n">x1</span> <span class="n">struct</span><span class="p">]</span> <span class="p">[</span><span class="mi">1</span><span class="n">x1</span> <span class="n">struct</span><span class="p">]</span> <span class="o">&gt;&gt;</span> <span class="n">fig</span><span class="o">.</span><span class="n">data</span><span class="p">{</span><span class="mi">1</span><span class="p">}</span> <span class="o">%</span> <span class="n">The</span> <span class="s1">&#39;type&#39;</span> <span class="n">of</span> <span class="n">this</span> <span class="n">trace</span> <span class="ow">is</span> <span class="s1">&#39;scatter&#39;</span><span class="o">.</span> <span class="n">scatter</span><span class="s1">&#39;s reference: #scatter</span> <span class="n">ans</span> <span class="o">=</span> <span class="n">xaxis</span><span class="p">:</span> <span class="s1">&#39;x1&#39;</span> <span class="o">%</span> <span class="n">more</span> <span class="n">about</span> <span class="n">scatter</span><span class="s1">&#39;s &#39;</span><span class="n">xaxis</span><span class="s1">&#39;: #scatter-xaxis</span> <span class="n">yaxis</span><span class="p">:</span> <span class="s1">&#39;y1&#39;</span> <span class="o">%</span> <span class="n">scatter</span><span class="s1">&#39;s &#39;</span><span class="n">yaxis</span><span class="s1">&#39; property: #scatter-yaxis</span> <span class="nb">type</span><span class="p">:</span> <span class="s1">&#39;scatter&#39;</span> <span class="n">visible</span><span class="p">:</span> <span class="mi">1</span> <span class="o">%</span> <span class="n">scatter</span><span class="s1">&#39;s &#39;</span><span class="n">visible</span><span class="s1">&#39; property: #scatter-visible</span> <span class="n">x</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="n">x100</span> <span class="n">double</span><span class="p">]</span> <span class="o">%</span> <span class="n">scatter</span><span class="s1">&#39;s &#39;</span><span class="n">x</span><span class="s1">&#39; property: #scatter-x</span> <span class="n">y</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="n">x100</span> <span class="n">double</span><span class="p">]</span> <span class="o">%</span> <span class="n">scatter</span><span class="s1">&#39;s &#39;</span><span class="n">y</span><span class="s1">&#39; property: #scatter-y</span> <span class="n">name</span><span class="p">:</span> <span class="s1">&#39;&#39;</span> <span class="o">%</span> <span class="n">scatter</span><span class="s1">&#39;s &#39;</span><span class="n">name</span><span class="s1">&#39; property: #scatter-name</span> <span class="n">mode</span><span class="p">:</span> <span class="s1">&#39;lines&#39;</span> <span class="o">%</span> <span class="n">scatter</span><span class="s1">&#39;s &#39;</span><span class="n">mode</span><span class="s1">&#39; property: #scatter-mode</span> <span class="n">line</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="n">x1</span> <span class="n">struct</span><span class="p">]</span> <span class="o">%</span> <span class="n">scatter</span><span class="s1">&#39;s &#39;</span><span class="n">line</span><span class="s1">&#39; property: #scatter-line</span> <span class="n">marker</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="n">x1</span> <span class="n">struct</span><span class="p">]</span> <span class="o">%</span> <span class="n">scatter</span><span class="s1">&#39;s &#39;</span><span class="n">marker</span><span class="s1">&#39; property: #scatter-marker</span> <span class="n">showlegend</span><span class="p">:</span> <span class="mi">1</span> <span class="o">%</span> <span class="n">scatter</span><span class="s1">&#39;s &#39;</span><span class="n">showlegend</span><span class="s1">&#39;: #scatter-marker</span> <span class="o">%%</span> <span class="n">Modify</span> <span class="ow">or</span> <span class="n">add</span> <span class="n">new</span> <span class="n">properties</span> <span class="n">to</span> <span class="n">this</span> <span class="n">trace</span> <span class="o">&gt;&gt;</span> <span class="n">fig</span><span class="o">.</span><span class="n">data</span><span class="p">{</span><span class="mi">1</span><span class="p">}</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;Current&#39;</span><span class="p">;</span> <span class="o">%</span> <span class="n">Update</span> <span class="n">the</span> <span class="n">legend</span> <span class="n">name</span> <span class="n">to</span> <span class="s1">&#39;Current&#39;</span> <span class="o">&gt;&gt;</span> <span class="n">fig</span><span class="o">.</span><span class="n">layout</span> <span class="o">%</span> <span class="n">layout</span> <span class="n">reference</span><span class="p">:</span> <span class="c1">#layout</span> <span class="n">ans</span> <span class="o">=</span> <span class="n">autosize</span><span class="p">:</span> <span class="mi">0</span> <span class="o">%</span> <span class="n">layout</span><span class="s1">&#39;s &#39;</span><span class="n">autosize</span><span class="s1">&#39;: #layout-autosize</span> <span class="n">margin</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="n">x1</span> <span class="n">struct</span><span class="p">]</span> <span class="o">%</span> <span class="n">layout</span><span class="s1">&#39;s &#39;</span><span class="n">margin</span><span class="s1">&#39;: #layout-margin</span> <span class="n">showlegend</span><span class="p">:</span> <span class="mi">0</span> <span class="o">%</span> <span class="n">layout</span><span class="s1">&#39;s &#39;</span><span class="n">showlegend</span><span class="s1">&#39;: #layout-showlegend</span> <span class="n">width</span><span class="p">:</span> <span class="mi">840</span> <span class="o">%</span> <span class="n">layout</span><span class="s1">&#39;s &#39;</span><span class="n">width</span><span class="s1">&#39;: #layout-width</span> <span class="n">height</span><span class="p">:</span> <span class="mi">630</span> <span class="o">%</span> <span class="n">layout</span><span class="s1">&#39;s &#39;</span><span class="n">height</span><span class="s1">&#39;: #layout-height</span> <span class="n">paper_bgcolor</span><span class="p">:</span> <span class="s1">&#39;rgb(255,255,255)&#39;</span> <span class="o">%</span> <span class="n">layout</span><span class="s1">&#39;s &#39;</span><span class="n">paper_bgcolor</span><span class="s1">&#39;: #layout-paper_bgcolor</span> <span class="n">hovermode</span><span class="p">:</span> <span class="s1">&#39;closest&#39;</span> <span class="o">%</span> <span class="n">layout</span><span class="s1">&#39;s &#39;</span><span class="n">hovermode</span><span class="s1">&#39;: #layout-hovermode</span> <span class="n">plot_bgcolor</span><span class="p">:</span> <span class="s1">&#39;rgba(0,0,0,0)&#39;</span> <span class="o">%</span> <span class="n">layout</span><span class="s1">&#39;s &#39;</span><span class="n">plot_bgcolor</span><span class="s1">&#39;: #layout-plot_bgcolor</span> <span class="n">xaxis1</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="n">x1</span> <span class="n">struct</span><span class="p">]</span> <span class="o">%</span> <span class="n">layout</span><span class="s1">&#39;s &#39;</span><span class="n">xaxis</span><span class="s1">&#39;: #layout-xaxis</span> <span class="n">yaxis1</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="n">x1</span> <span class="n">struct</span><span class="p">]</span> <span class="o">%</span> <span class="n">layout</span><span class="s1">&#39;s &#39;</span><span class="n">yaxis</span><span class="s1">&#39;: #layout-yaxis</span> <span class="n">annotations</span><span class="p">:</span> <span class="p">{[</span><span class="mi">1</span><span class="n">x1</span> <span class="n">struct</span><span class="p">]}</span> <span class="o">%</span> <span class="n">layout</span><span class="s1">&#39;s &#39;</span><span class="n">annotations</span><span class="s1">&#39;: #layout-annotations</span> <span class="o">&gt;&gt;</span> <span class="n">fig</span><span class="o">.</span><span class="n">layout</span><span class="o">.</span><span class="n">showlegend</span> <span class="o">=</span> <span class="n">true</span><span class="p">;</span> <span class="o">%</span> <span class="n">layout</span><span class="s1">&#39;s &#39;</span><span class="n">showlegend</span><span class="s1">&#39;: #layout-showlegend</span> <span class="o">&gt;&gt;</span> <span class="n">fig</span><span class="o">.</span><span class="n">layout</span><span class="o">.</span><span class="n">legend</span> <span class="o">=</span> <span class="n">struct</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span> <span class="o">%</span> <span class="n">Update</span> <span class="n">the</span> <span class="n">legend</span><span class="p">:</span> <span class="c1">#layout-legend</span> <span class="o">&gt;&gt;</span> <span class="n">fig</span><span class="o">.</span><span class="n">layout</span><span class="o">.</span><span class="n">title</span> <span class="o">=</span> <span class="s1">&#39;Modified plot&#39;</span><span class="p">;</span> <span class="o">%%</span> <span class="n">Set</span> <span class="n">the</span> <span class="n">filename</span><span class="p">,</span> <span class="ow">and</span> <span class="n">overwrite</span> <span class="n">the</span> <span class="n">plot</span> <span class="k">if</span> <span class="n">it</span> <span class="n">already</span> <span class="n">exists</span> <span class="o">&gt;&gt;</span> <span class="n">fig</span><span class="o">.</span><span class="n">PlotOptions</span><span class="o">.</span><span class="n">FileName</span> <span class="o">=</span> <span class="s1">&#39;Customized plot&#39;</span><span class="p">;</span> <span class="o">&gt;&gt;</span> <span class="n">fig</span><span class="o">.</span><span class="n">PlotOptions</span><span class="o">.</span><span class="n">FileOpt</span> <span class="o">=</span> <span class="s1">&#39;overwrite&#39;</span><span class="p">;</span> <span class="o">%%</span> <span class="n">Use</span> <span class="n">offline</span> <span class="o">%%</span> <span class="n">Download</span> <span class="n">the</span> <span class="n">offline</span> <span class="n">bundle</span> <span class="o">&gt;&gt;</span> <span class="n">getplotlyoffline</span><span class="p">(</span><span class="s1">&#39;https://cdn.plot.ly/plotly-latest.min.js&#39;</span><span class="p">)</span> <span class="o">&gt;&gt;</span> <span class="n">fig</span><span class="o">.</span><span class="n">PlotOptions</span><span class="o">.</span><span class="n">Offline</span> <span class="o">=</span> <span class="n">true</span><span class="p">;</span> <span class="o">%%</span> <span class="n">Send</span> <span class="n">to</span> <span class="n">plotly</span> <span class="o">&gt;&gt;</span> <span class="n">fig</span><span class="o">.</span><span class="n">plotly</span> </pre></div> </div> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> </div> <div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <h4 id="Core-Functions">Core Functions<a class="anchor-link" href="#Core-Functions">&#194;&#182;</a></h4> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> </div> <div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p><code>fig2plotly.m</code>: Plot a MATLAB<sup>&reg;</sup> figure object with Plotly <code>fig2plotly.m</code> converts MATLAB<sup>&reg;</sup> figures to online Plotly graphs. MATLAB<sup>&reg;</sup> describes figures differently than Plotly. Plotly's MATLAB<sup>&reg;</sup> library crawls the MATLAB<sup>&reg;</sup> figure objects and translates the MATLAB<sup>&reg;</sup> attributes into the structure that Plotly uses to describe and draw data visualizations.</p> </div> </div> </div> <div class="cell border-box-sizing code_cell rendered"> <div class="input"> <div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div> <div class="inner_cell"> <div class="input_area"> <div class=" highlight hl-ipython2"><pre><span></span><span class="p">[</span><span class="n">INPUT</span><span class="p">]:</span> <span class="n">resp</span> <span class="o">=</span> <span class="n">fig2plotly</span><span class="p">()</span> <span class="n">resp</span> <span class="o">=</span> <span class="n">fig2plotly</span><span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="n">resp</span> <span class="o">=</span> <span class="n">fig2plotly</span><span class="p">(</span><span class="n">gcf</span><span class="p">)</span> <span class="n">resp</span> <span class="o">=</span> <span class="n">fig2plotly</span><span class="p">(</span><span class="n">f</span><span class="p">,</span><span class="s1">&#39;property&#39;</span><span class="p">,</span><span class="n">value</span><span class="p">,</span> <span class="o">...</span> <span class="p">)</span> <span class="n">resp</span> <span class="o">=</span> <span class="n">fig2plotly</span><span class="p">(</span><span class="n">gcf</span><span class="p">,</span><span class="s1">&#39;property&#39;</span><span class="p">,</span><span class="n">value</span><span class="p">,</span> <span class="o">...</span> <span class="p">)</span> <span class="p">[</span><span class="n">WHERE</span><span class="p">]:</span> <span class="n">gcf</span> <span class="o">-</span> <span class="n">root</span> <span class="n">figure</span> <span class="nb">object</span> <span class="n">handle</span> <span class="p">[</span><span class="n">double</span><span class="p">]</span><span class="o">.</span> <span class="n">f</span> <span class="o">-</span> <span class="n">root</span> <span class="n">figure</span> <span class="nb">object</span> <span class="p">[</span><span class="n">struct</span><span class="p">]</span> <span class="o">&gt;&gt;</span> <span class="n">f</span> <span class="o">=</span> <span class="n">get</span><span class="p">(</span><span class="n">gcf</span><span class="p">)</span> <span class="p">[</span><span class="n">PROPERTIES</span><span class="p">]:</span> <span class="s1">&#39;name&#39;</span> <span class="o">-</span> <span class="n">name</span> <span class="n">of</span> <span class="n">the</span> <span class="n">plot</span> <span class="p">[</span><span class="n">string</span><span class="p">][</span><span class="s1">&#39;untitled&#39;</span><span class="p">]</span> <span class="s1">&#39;strip&#39;</span> <span class="o">-</span> <span class="n">use</span> <span class="n">plotly</span> <span class="n">default</span> <span class="n">styling</span> <span class="p">[</span><span class="n">boolean</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="s1">&#39;open&#39;</span> <span class="o">-</span> <span class="n">opens</span> <span class="n">a</span> <span class="n">browser</span> <span class="k">with</span> <span class="n">plot</span> <span class="n">result</span> <span class="p">[</span><span class="n">boolean</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="p">[</span><span class="n">OUTPUT</span><span class="p">]:</span> <span class="n">resp</span> <span class="o">-</span> <span class="n">results</span> <span class="n">info</span> <span class="n">of</span> <span class="n">the</span> <span class="n">plot</span> <span class="p">[</span><span class="n">struct</span><span class="p">]</span> <span class="n">resp</span><span class="o">.</span><span class="p">[</span><span class="n">url</span><span class="p">,</span><span class="n">warning</span><span class="p">,</span><span class="n">message</span><span class="p">,</span><span class="n">filename</span><span class="p">,</span><span class="n">error</span><span class="p">]</span> </pre></div> </div> </div> </div> </div> <div class="cell border-box-sizing code_cell rendered"> <div class="input"> <div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div> <div class="inner_cell"> <div class="input_area"> <div class=" highlight hl-ipython2"><pre><span></span><span class="n">api_path</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;/Users/chuckbronson/Documents/PLOTLY/MATLAB_API_DEV/DEV/TEST_PLOTS&#39;</span><span class="p">);</span> <span class="n">addpath</span><span class="p">(</span><span class="n">genpath</span><span class="p">(</span><span class="n">api_path</span><span class="p">));</span> <span class="n">load</span> <span class="n">fitdata</span> <span class="n">x</span> <span class="n">y</span> <span class="n">yfit</span><span class="p">;</span> <span class="n">fig</span> <span class="o">=</span> <span class="n">figure</span><span class="p">;</span> <span class="n">scatter</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="s1">&#39;k&#39;</span><span class="p">);</span> <span class="n">line</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">yfit</span><span class="p">,</span> <span class="s1">&#39;color&#39;</span><span class="p">,</span> <span class="s1">&#39;k&#39;</span><span class="p">,</span> <span class="s1">&#39;linestyle&#39;</span><span class="p">,</span> <span class="s1">&#39;-&#39;</span><span class="p">,</span> <span class="s1">&#39;linewidth&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span> <span class="n">line</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">yfit</span> <span class="o">+</span> <span class="mf">0.3</span><span class="p">,</span> <span class="s1">&#39;color&#39;</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">,</span> <span class="s1">&#39;linestyle&#39;</span><span class="p">,</span> <span class="s1">&#39;--&#39;</span><span class="p">,</span> <span class="s1">&#39;linewidth&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span> <span class="n">line</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">yfit</span> <span class="o">-</span> <span class="mf">0.3</span><span class="p">,</span> <span class="s1">&#39;color&#39;</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">,</span> <span class="s1">&#39;linestyle&#39;</span><span class="p">,</span> <span class="s1">&#39;--&#39;</span><span class="p">,</span> <span class="s1">&#39;linewidth&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span> <span class="n">legend</span><span class="p">(</span><span class="s1">&#39;Data&#39;</span><span class="p">,</span> <span class="s1">&#39;Localized Regression&#39;</span><span class="p">,</span> <span class="s1">&#39;Confidence Intervals&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span> <span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;X&#39;</span><span class="p">);</span> <span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;Noisy&#39;</span><span class="p">);</span> <span class="o">%%</span><span class="k">Just</span> ONE line of Plotly Code!%% resp = fig2plotly(fig,&#39;filename&#39;,&#39;matlab_overview_1&#39;,&#39;strip&#39;,false); resp.url </pre></div> </div> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> </div> <div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p><code>ans = https://plotly.com/~matlab_user_guide/661/noisy-vs-x/</code></p> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> </div> <div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <iframe frameborder="0" seamless="seamless" scrolling="no" src="https://plotly.com/~matlab_user_guide/661.embed" width="80%" height="500px"> </iframe> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> </div> <div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>The above plot is the ouptut from calling the <code>scatter.m</code> and <code>line.m</code> functions inherent in MATLAB<sup>&reg;</sup>. Using the <code>fig2plotly.m</code> function, we are able to extract the relevant data from the MATLAB<sup>&reg;</sup> figure object and throw the output over to our Plotly account! The returned response variable, resp, is a structure array which contains a url field with the address of our plot.</p> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> </div> <div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <h4 id="Offline-Usage">Offline Usage<a class="anchor-link" href="#Offline-Usage">&#194;&#182;</a></h4><p>We can make a Plotly graph in Matlab offline which will be saved as an html file to your current working directory using Plotly Offline. These html files will contain all of the necessary dependencies to render the plot within a browser.</p> </div> </div> </div> <div class="cell border-box-sizing code_cell rendered"> <div class="input"> <div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div> <div class="inner_cell"> <div class="input_area"> <div class=" highlight hl-ipython2"><pre><span></span><span class="n">X</span> <span class="o">=</span> <span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">2</span><span class="o">*</span><span class="n">pi</span><span class="p">,</span><span class="mi">50</span><span class="p">)</span><span class="s1">&#39;;</span> <span class="n">Y</span> <span class="o">=</span> <span class="p">[</span><span class="n">cos</span><span class="p">(</span><span class="n">X</span><span class="p">),</span> <span class="mf">0.5</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">X</span><span class="p">)];</span> <span class="n">stem</span><span class="p">(</span><span class="n">X</span><span class="p">,</span><span class="n">Y</span><span class="p">)</span> <span class="n">fig2plotly</span><span class="p">(</span><span class="n">gcf</span><span class="p">,</span><span class="s1">&#39;offline&#39;</span><span class="p">,</span><span class="n">true</span><span class="p">,</span><span class="s1">&#39;filename&#39;</span><span class="p">,</span><span class="s1">&#39;offline-graph&#39;</span><span class="p">);</span> </pre></div> </div> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> </div> <div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p><img src="http://i.imgur.com/HeUJ7fw.png" width="80%" height="250px" alt="self-hosted matlab online"></p> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> </div> <div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <h4 id="Retrieve-a-Figure">Retrieve a Figure<a class="anchor-link" href="#Retrieve-a-Figure">&#194;&#182;</a></h4><p><code>getplotlyfig.m</code>: Get data, style, and layout from the plots stored online One of Plotly's secret powers is the ability to translate between MATLAB's structure/cell array syntax and JSON. This allows a smooth transition between your figures in MATLAB<sup>&reg;</sup> and those stored in your Plotly account. <code>getplotlyfig.m</code> allows you to grab the data, style, and layout information from your plots saved online. In fact, <code>getploylyfig.m</code> lets you grab the data, Style and layout of <b>anyone's</b> Plotly plots (as long as they are made public) - not just your own! See a graph you like online? Grab the style, layout, and data and make one for yourself.</p> </div> </div> </div> <div class="cell border-box-sizing code_cell rendered"> <div class="input"> <div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div> <div class="inner_cell"> <div class="input_area"> <div class=" highlight hl-ipython2"><pre><span></span><span class="p">[</span><span class="n">INPUT</span><span class="p">]:</span> <span class="n">plotlyfigure</span> <span class="o">=</span> <span class="n">getplotlyfig</span><span class="p">(</span><span class="s1">&#39;file_owner&#39;</span><span class="p">,</span><span class="n">file_id</span><span class="p">)</span> <span class="p">[</span><span class="n">WHERE</span><span class="p">]:</span> <span class="n">file_owner</span> <span class="o">-</span> <span class="n">user</span> <span class="n">name</span> <span class="n">associated</span> <span class="k">with</span> <span class="n">the</span> <span class="n">plot</span> <span class="p">[</span><span class="n">string</span><span class="p">]</span><span class="o">.</span> <span class="n">file_id</span> <span class="o">-</span> <span class="n">number</span> <span class="n">identifier</span> <span class="n">associated</span> <span class="k">with</span> <span class="n">the</span> <span class="n">plot</span> <span class="p">[</span><span class="n">string</span><span class="p">]</span> <span class="p">[</span><span class="n">OUTPUT</span><span class="p">]:</span> <span class="n">plotlyfigure</span> <span class="o">-</span> <span class="n">results</span> <span class="n">info</span> <span class="n">of</span> <span class="n">the</span> <span class="n">plot</span> <span class="p">[</span><span class="n">struct</span><span class="p">]</span> <span class="n">plotlyfigure</span><span class="o">.</span><span class="p">[</span><span class="n">data</span><span class="p">,</span><span class="n">layout</span><span class="p">]</span> </pre></div> </div> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> </div> <div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>Here we can use <code>getplotlyfig.m</code> and have a go at changing the bar and line colours on a different graph: <a href="https://plotly.com/~matlab_user_guide/664/">https://plotly.com/~matlab_user_guide/664/</a> !</p> </div> </div> </div> <div class="cell border-box-sizing code_cell rendered"> <div class="input"> <div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div> <div class="inner_cell"> <div class="input_area"> <div class=" highlight hl-ipython2"><pre><span></span><span class="o">%%</span><span class="k">matlab</span> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % GET PLOTLY FIG! % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% plotlyfigure = getplotlyfig(&#39;matlab_user_guide&#39;,&#39;664&#39;); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % DATA/STYLE % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % COLOUR CHOICES col1 = &#39;#3C8A22&#39;; col2 = &#39;#097054&#39;; col3 = &#39;black&#39;; % LINE STYLE plotlyfigure.data{1}.line.width = 10; plotlyfigure.data{1}.line.color = col2; plotlyfigure.data{1}.opacity = 0.7; plotlyfigure.data{1}.name = &#39;Infection Rate&#39;; % BAR CHART STYLE plotlyfigure.data{2}.marker.color = col1; plotlyfigure.data{2}.marker.line.width = 2; plotlyfigure.data{2}.marker.line.color = col3; plotlyfigure.data{2}.opacity = 0.7; plotlyfigure.data{2}.name = &#39;Cases&#39;; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % LAYOUT % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Y2 AXIS STYLE plotlyfigure.layout.yaxis2.titlefont.color = col3; plotlyfigure.layout.yaxis2.tickfont.color = col2; plotlyfigure.layout.yaxis2.tickcolor = col2; plotlyfigure.layout.yaxis2.linecolor = col2; plotlyfigure.layout.yaxis2.linewidth = 2; % X AXIS STYLE plotlyfigure.layout.xaxis.mirror = 0; plotlyfigure.layout.xaxis.showline = 0; % BAR LAYOUT plotlyfigure.layout.bargap = 0.2; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % ARGS % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% args.layout = plotlyfigure.layout; args.filename = &#39;matlab_overview_5&#39;; args.fileopt = &#39;overwrite&#39;; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % PLOTLY % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% resp = plotly(plotlyfigure.data,args); resp.url </pre></div> </div> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> </div> <div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <iframe frameborder="0" seamless="seamless" scrolling="no" src="https://plotly.com/~matlab_user_guide/665/cases-vs-years.embed" width="80%" height="500px"> </iframe> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> </div> <div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <h4 id="Export-Static-Image">Export Static Image<a class="anchor-link" href="#Export-Static-Image">&#194;&#182;</a></h4><p><code>saveplotlyfig.m</code>: save your MATLAB<sup>&reg;</sup> figure as an image using Plotly. <code>saveplotlyfig.m</code> allows you to convert your MATLAB<sup>&reg;</sup> figures into static images (.png, .svg, .pdf, .jpeg) using Plotly.</p> </div> </div> </div> <div class="cell border-box-sizing code_cell rendered"> <div class="input"> <div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div> <div class="inner_cell"> <div class="input_area"> <div class=" highlight hl-ipython2"><pre><span></span><span class="p">[</span><span class="n">INPUT</span><span class="p">]:</span> <span class="n">saveplotlyfig</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">format</span> <span class="p">{</span><span class="n">otional</span><span class="p">})</span> <span class="n">saveplotlyfig</span><span class="p">(</span><span class="n">plotlyfigure</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">format</span> <span class="p">{</span><span class="n">optional</span><span class="p">})</span> <span class="n">NOTE</span><span class="p">:</span> <span class="k">if</span> <span class="n">format</span> <span class="ow">is</span> <span class="n">unspecified</span><span class="p">,</span> <span class="n">saveplotlyfig</span> <span class="n">will</span> <span class="n">use</span> <span class="n">the</span> <span class="n">image</span> <span class="n">format</span> <span class="n">given</span> <span class="n">by</span> <span class="n">the</span> <span class="n">extension</span> <span class="n">of</span> <span class="n">filename</span><span class="o">.</span> <span class="n">If</span> <span class="n">filename</span> <span class="n">does</span> <span class="ow">not</span> <span class="n">have</span> <span class="n">an</span> <span class="n">explicit</span> <span class="n">extension</span> <span class="p">(</span><span class="n">ex</span><span class="p">:</span> <span class="n">filename</span><span class="o">.</span><span class="n">pdf</span><span class="p">),</span> <span class="n">the</span> <span class="n">default</span> <span class="n">format</span> <span class="n">of</span> <span class="n">PNG</span> <span class="n">will</span> <span class="n">be</span> <span class="n">used</span> <span class="k">for</span> <span class="n">the</span> <span class="n">conversion</span><span class="o">.</span> <span class="p">[</span><span class="n">WHERE</span><span class="p">]:</span> <span class="n">data</span> <span class="o">-</span> <span class="n">data</span><span class="o">/</span><span class="n">style</span> <span class="n">of</span> <span class="n">plot</span> <span class="p">[</span><span class="n">cell</span> <span class="n">array</span><span class="p">]</span> <span class="n">plotlyfigure</span><span class="o">.</span><span class="n">data</span> <span class="o">-</span> <span class="n">data</span><span class="o">/</span><span class="n">style</span> <span class="n">of</span> <span class="n">plot</span> <span class="p">[</span><span class="n">cell</span> <span class="n">array</span><span class="p">]</span> <span class="n">plotlyfigure</span><span class="o">.</span><span class="n">layout</span> <span class="o">-</span> <span class="n">layout</span> <span class="n">of</span> <span class="n">plot</span> <span class="p">[</span><span class="n">struct</span><span class="p">]</span> <span class="n">filename</span> <span class="o">-</span> <span class="n">name</span> <span class="n">of</span> <span class="n">image</span> <span class="n">to</span> <span class="n">be</span> <span class="n">saved</span> <span class="p">[</span><span class="n">string</span><span class="p">]</span> <span class="p">[</span><span class="n">OUTPUT</span><span class="p">]:</span> <span class="n">Image</span> <span class="s1">&#39;filename&#39;</span> <span class="n">of</span> <span class="n">the</span> <span class="n">specified</span> <span class="n">format</span> <span class="p">(</span><span class="n">PNG</span><span class="p">,</span> <span class="n">PDF</span><span class="p">,</span> <span class="n">JPEG</span><span class="p">,</span> <span class="ow">or</span> <span class="n">SVG</span><span class="p">)</span> <span class="n">saved</span> <span class="n">to</span> <span class="n">your</span> <span class="n">working</span> <span class="n">directory</span><span class="o">.</span> </pre></div> </div> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> </div> <div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>Let's have a look at <code>saveplotlyfig.m</code> to see how it works. Check out this next plot that was featured on the MATLAB<sup>&reg;</sup> plot gallery.</p> </div> </div> </div> <div class="cell border-box-sizing code_cell rendered"> <div class="input"> <div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div> <div class="inner_cell"> <div class="input_area"> <div class=" highlight hl-ipython2"><pre><span></span><span class="o">%%</span><span class="k">matlab</span> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % FROM MATLAB<sup>&reg;</sup> PLOT GALLERY % % http://www.mathworks.com/discovery/gallery.html % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Load Morse data load MDdata dissimilarities dist1 dist2 dist3 % Plot the first set of data in blue fig = figure; plot(dissimilarities, dist1, &#39;bo&#39;); hold on; % Plot the second set of data in red plot(dissimilarities, dist2, &#39;r+&#39;); % Plot the third set of data in green plot(dissimilarities, dist3, &#39;g^&#39;); % Add title and axis labels title(&#39;Morse Signal Analysis&#39;); xlabel(&#39;Dissimilarities&#39;); ylabel(&#39;Distances&#39;); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % PLOTLY % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% filename = &#39;matlab_overview_8&#39;; resp = fig2plotly(fig,&#39;filename&#39;,filename,&#39;strip&#39;,false); resp.url </pre></div> </div> </div> </div> </div> <div class="cell border-box-sizing code_cell rendered"> <div class="input"> <div class="prompt input_prompt">In&nbsp;[&nbsp;]:</div> <div class="inner_cell"> <div class="input_area"> <div class=" highlight hl-ipython2"><pre><span></span><span class="n">plotlyfigure</span> <span class="o">=</span> <span class="n">getplotlyfig</span><span class="p">(</span><span class="s1">&#39;matlab_user_guide&#39;</span><span class="p">,</span><span class="s1">&#39;670&#39;</span><span class="p">);</span> <span class="n">filename</span> <span class="o">=</span> <span class="s1">&#39;morse.png&#39;</span><span class="p">;</span> <span class="n">saveplotlyfig</span><span class="p">(</span><span class="n">plotlyfigure</span><span class="p">,</span><span class="n">filename</span><span class="p">)</span> </pre></div> </div> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> </div> <div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p>Boom! <b>morse.png</b> has been automatically saved to our working directory. Let's have a look.</p> </div> </div> </div> <div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt"> </div> <div class="inner_cell"> <div class="text_cell_render border-box-sizing rendered_html"> <p><img src="https://plotly.com/~matlab_user_guide/670.png" alt="https://plotly.com/~matlab_user_guide/670.png"></p> </div> </div> </div> </section> <!--End Plotly Basics Section--> </section> </div> </main> <script> var array = []; $('.tutorial-content :header:not(h6)').each(function (i, e) { var item = $(e); var itemText = item.text(); var hash = itemText.replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, '-').replace(/^-+|-+$/g, '').toLowerCase(); item.attr("id", hash); array.push({text: itemText, tag: item.prop("tagName"), hash: hash}); }); $("#nav_header_insertion_list").html(array.map(function(entry) { var text = entry.text.replace(/[^a-z0-9\s\.:\-\?\!\(\))]/gi, ''); if(entry.tag.toLowerCase() < "h4"){ return('<li class="--sidebar-item"><a href="#' + entry.hash + '">' + text + '</a></li>'); } else { return('<li class="--sidebar-item"><a href="#' + entry.hash + '">' + text + '</a></li>'); } }).join("")); //$(".tutorial-content :header:not(h6)").append( "\<div class=\"icon copy\" data-tooltip=\"Click to copy direct link\"><svg style=\"width:24px;height:24px\" viewBox=\"0 0 24 24\"><path fill=\"#000000\" d=\"M10.59,13.41C11,13.8 11,14.44 10.59,14.83C10.2,15.22 9.56,15.22 9.17,14.83C7.22,12.88 7.22,9.71 9.17,7.76V7.76L12.71,4.22C14.66,2.27 17.83,2.27 19.78,4.22C21.73,6.17 21.73,9.34 19.78,11.29L18.29,12.78C18.3,11.96 18.17,11.14 17.89,10.36L18.36,9.88C19.54,8.71 19.54,6.81 18.36,5.64C17.19,4.46 15.29,4.46 14.12,5.64L10.59,9.17C9.41,10.34 9.41,12.24 10.59,13.41M13.41,9.17C13.8,8.78 14.44,8.78 14.83,9.17C16.78,11.12 16.78,14.29 14.83,16.24V16.24L11.29,19.78C9.34,21.73 6.17,21.73 4.22,19.78C2.27,17.83 2.27,14.66 4.22,12.71L5.71,11.22C5.7,12.04 5.83,12.86 6.11,13.65L5.64,14.12C4.46,15.29 4.46,17.19 5.64,18.36C6.81,19.54 8.71,19.54 9.88,18.36L13.41,14.83C14.59,13.66 14.59,11.76 13.41,10.59C13,10.2 13,9.56 13.41,9.17Z\"/> </svg> </div>"); </script> <footer class="--footer-main"> <section class="--footer-top"> <div class="--wrap"> <ul class="--footer-body"> <li class="--footer-column"> <h6 style="color:#119dff" class="--footer-heading">JOIN OUR MAILING LIST</h6>&#x9;&#x9;&#x9; <ul> &#x9;&#x9;&#x9;&#x9; <li> <p class="subscribe-text"> Sign up to stay in the loop with all things Plotly — from Dash Club to product updates, webinars, and more!</p> <a href="https://go.plot.ly/subscription" class="subscribe-button" target="_blank"> Subscribe </a> </li> </ul> </li> &#x9;&#x9; <li class="--footer-column"> <h6 style="color:#e763fa" class="--footer-heading">Products</h6>&#x9;&#x9;&#x9; <ul> <li><a href="https://plotly.com/dash/" target="_self">Dash</a></li> &#x9;&#x9;&#x9;&#x9; &#x9;&#x9;&#x9;&#x9; <li><a href="https://plotly.com/consulting-and-oem/" target="_self">Consulting and Training</a></li> </ul> </li> &#x9;&#x9; <li class="--footer-column"> <h6 style="color:#636efa" class="--footer-heading">Pricing</h6>&#x9;&#x9;&#x9; <ul> <li><a href="https://plotly.com/get-pricing/" target="_self">Enterprise Pricing</a></li> &#x9;&#x9;&#x9;&#x9; </ul> </li> &#x9;&#x9; <li class="--footer-column"> <h6 style="color:#00cc96" class="--footer-heading">About Us</h6>&#x9;&#x9;&#x9; <ul> <li><a href="https://plotly.com/careers" target="_self">Careers</a></li> &#x9;&#x9;&#x9;&#x9; <li><a href="https://plotly.com/resources/" target="_self">Resources</a></li> &#x9;&#x9;&#x9;&#x9; <li><a href="https://medium.com/@plotlygraphs" target="_self">Blog</a></li> &#x9;&#x9;&#x9;&#x9; </ul> </li> &#x9;&#x9; <li class="--footer-column"> <h6 style="color:#EF553B" class="--footer-heading">Support</h6>&#x9;&#x9;&#x9; <ul> <li><a href="https://community.plot.ly/" target="_self">Community Support</a></li> &#x9;&#x9;&#x9;&#x9; <li><a href="https://plotly.com/graphing-libraries" target="_self">Documentation</a></li> &#x9;&#x9;&#x9;&#x9; </ul> </li> </ul> </div> </section> <section class="--footer-meta"> <div class="--wrap"> <div class="left"> <article class="--copyright">Copyright &copy; 2024 Plotly. All rights reserved.</article> </div> <div class="right"> <article class="--tos"><a href="https://community.plotly.com/tos" target="_blank">Terms of Service</a> </article> <article class="--privacy"><a href="https://plotly.com/privacy/" target="_blank">Privacy Policy</a> </article> </div> </div> <div id="markprompt" /> </section> </footer> <div class="modal" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content" id="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> <span style="float: left; padding-top:13px; padding-right:10px;"><i class="fa fa-search fa-lg"></i></span> <input id="search-input" class="search-input" type="text" placeholder="" /> </div> <div class="modal-body" id="modal-body"> <div id="search-results" class="search-results"> <div id="primary-search-results" class="primary-search-results"></div> <div id="schema-search-results" class="schema-search-results"></div> </div> </div> </div> </div> </div> <script> window.plotly_doc_language = "matlab"; </script> <!-- ALGOLIA SEARCH --> <script> window.ALGOLIA_CONFIG = { 'applicationId': '7EK9KHJW8M', 'indexName': 'matlab_docs', 'apiKey': '4dae07ded6a721de73bde7356eec9280', 'baseurl': '/' } </script> <script id="algolia__template" type="text/template"> <div class="algolia__result"> <a class="algolia__result-link" onClick="$('#myModal').modal('toggle')" href="/{{ permalink }}">{{{ _highlightResult.name.value }}}</a> <div class="algolia__result-text">{{{ _highlightResult.description.value }}}</div> </div> </script> <script id="algolia__secondary-template" type="text/template"> <div class="algolia__secondary-result"> <a class="algolia__result-link" onClick="$('#myModal').modal('toggle')" href="/{{ permalink }}">{{{ _highlightResult.name.value }}}</a> <div class="algolia__result-text">{{{ _highlightResult.description.value }}}</div> </div> </script> <script id="algolia__template--no-results" type="text/template">No results found.</script> <script src="//cdn.jsdelivr.net/hogan.js/3.0.2/hogan.min.js"></script> <script src="/all_static/javascripts/algolia/algolia.js"></script> <!-- Hash offset Script --> <script src="/all_static//javascripts/hash_offset.js"></script> <!-- Image Hover Script --> <script src="/all_static/javascripts/imghover.js"></script> <script src="/all_static/javascripts/improve.js?version=2024-11-19-16-02"></script> <!-- code highlighting --> <!--<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/highlight.min.js"></script> <script src="/all_static/javascripts/highlight.line-numbers.js"></script>--> <script src="/all_static/javascripts/highlight/highlight.min.js"></script> <script src="/all_static/javascripts/highlight/julia.min.js"></script> <script src="/all_static/javascripts/highlight.line-numbers.js"></script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10