MATLAB Community

MATLAB, community & more

Plotly Plots MATLAB

Here’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 using a variety of different APIs and programming languages, one of which is MATLAB.

Here’s a quick example to show you how it works. Let’s suppose you have some data. Say, the per capita consumption of margarine in the US (in pounds). Mmmm. Margarine.

yrs = 2000:2009;
margarineConsumption = [8.2 7 6.5 5.3 5.2 4 4.6 4.5 4.2 3.7];


As soon as you see the margarine data, you think to yourself “Wait a second! Where have I seen that trend before?” 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’s do a plotyy.

maineDivorceRate = [5 4.7 4.6 4.4 4.3 4.1 4.2 4.2 4.2 4.1];


Sure enough, the fit is remarkable*. Now let’s say we want to share our plot as an interactive web page. After adding the Plotly API code to your path, just type


and you get a link to a web page like this:


Cool! Follow the link to try out the interaction.

* The remarkable margarine-divorce correlation was unearthed by Tyler Vigen on his fascinating Spurious Correlations page.

  • print


To leave a comment, please click here to sign in to your MathWorks Account or create a new one.