{"id":2709,"date":"2014-05-28T08:55:04","date_gmt":"2014-05-28T13:55:04","guid":{"rendered":"https:\/\/blogs.mathworks.com\/community\/?p=2709"},"modified":"2017-05-01T08:06:44","modified_gmt":"2017-05-01T12:06:44","slug":"plotly-plots-matlab","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/community\/2014\/05\/28\/plotly-plots-matlab\/","title":{"rendered":"Plotly Plots MATLAB"},"content":{"rendered":"<p>Here&#8217;s a quick post to tell you about a nifty service called <a href=\"https:\/\/plot.ly\">Plotly<\/a>. The basic idea is that you can create nice-looking interactive plots right in your web browser. You can generate the plots using a variety of different <a href=\"https:\/\/plot.ly\/api\/\">APIs and programming languages<\/a>, one of which is MATLAB.<\/p>\n<p>Here&#8217;s a quick example to show you how it works. Let&#8217;s suppose you have some data. Say, the per capita consumption of margarine in the US (in pounds). Mmmm. Margarine.<\/p>\n<p><code>yrs = 2000:2009;<br \/>\nmargarineConsumption = [8.2 7 6.5 5.3 5.2 4 4.6 4.5 4.2 3.7];<br \/>\nplot(yrs,margarineConsumption)<\/code><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2711\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/margarine.png\" alt=\"margarine\" width=\"560\" height=\"420\" \/><\/p>\n<p>As soon as you see the margarine data, you think to yourself &#8220;Wait a second! Where have I seen that trend before?&#8221; A moment of reflection, and suddenly it hits you: Maine divorce rates! That margarine plot is a dead ringer for divorce rates in Maine. Let&#8217;s do a <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/plotyy.html\">plotyy<\/a>.<\/p>\n<p><code>maineDivorceRate = [5 4.7 4.6 4.4 4.3 4.1 4.2 4.2 4.2 4.1];<br \/>\nplotyy(yrs,margarineConsumption,yrs,maineDivorceRate)<\/code><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2712\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/plotyy.png\" alt=\"plotyy\" width=\"560\" height=\"420\" \/><\/p>\n<p>Sure enough, the fit is remarkable*. Now let&#8217;s say we want to share our plot as an interactive web page. After adding the Plotly API code to your path, just type<\/p>\n<p><code>fig2plotly<\/code><\/p>\n<p>and you get a link to a web page like this:<\/p>\n<p><a href=\"https:\/\/plot.ly\/~NedGulley\/7\/\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2716\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/plotly.png\" alt=\"plotly\" width=\"494\" height=\"377\" \/><\/a><\/p>\n<p>Cool! <a href=\"https:\/\/plot.ly\/~NedGulley\/7\/\">Follow the link<\/a> to try out the interaction.<\/p>\n<p>* The <a href=\"\">remarkable margarine-divorce correlation<\/a> was unearthed by Tyler Vigen on his fascinating <a href=\"http:\/\/www.tylervigen.com\/\">Spurious Correlations<\/a> page.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/community\/files\/margarine.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>Here&#8217;s a quick post to tell you about a nifty service called Plotly. The basic idea is that you can create nice-looking interactive plots right in your web browser. You can generate the plots&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/community\/2014\/05\/28\/plotly-plots-matlab\/\">read more >><\/a><\/p>\n","protected":false},"author":69,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/2709"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/users\/69"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/comments?post=2709"}],"version-history":[{"count":15,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/2709\/revisions"}],"predecessor-version":[{"id":4563,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/2709\/revisions\/4563"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/media?parent=2709"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/categories?post=2709"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/tags?post=2709"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}