® graphing library to make interactive, publication-quality graphs online.> ® graphing library to make interactive, publication-quality graphs online./> ® graphing library to make interactive, publication-quality graphs online./>

Getting Started with Plotly and Chart Studio in MATLAB®

Get started with Plotly's MATLAB® graphing library to make interactive, publication-quality graphs online.


Installation

If you have not done so already, download and uncompress the Plotly Graphing Library for MATLAB®.

Initialization

In your MATLAB® console, begin by locating the downloaded directory, and running plotlysetup_online().

cd ~/Downloads/plotly-graphing-library-for-matlab-master
plotlysetup_online('DemoAccount', 'lr1c37zw81')
Click to copy

You'll need to replace "DemoAccount" and "lr1c37zw81" with your Plotly username and API key.

Find my API key.

You only have to set this up if it's your first time using a Plotly API.

This will set up your credentials and import the Plotly library into your MATLAB® toolboxes. You can now delete the downloaded folder.

Special Instructions for Chart Studio Enterprise Users

Your API key for a Chart Studio Enterprise account will be different from an account on the Plotly cloud. Visit https://plotly.your-company.com/settings/api/ to find your Chart Studio Enterprise API key. Remember to replace "your-company.com" with the URL of your Chart Studio Enterprise server.

Additionally, you'll have to change the MATLAB® Open Source Graphing Library endpoint so that it points to your company's Plotly server instead of Plotly's cloud. In your MATLAB® console, enter:


saveplotlyconfig('https://plotly.your-company.com', 'https://stream-plotly.your-company.com')
Click to copy

Alternatively, if you'd like to set your configuration to create private plots by default you should enter:


saveplotlyconfig('https://plotly.your-company.com', 'https://stream-plotly.your-company.com', 'private')
Click to copy

Make sure to replace "your-company.com" with the URL of your Chart Studio Enterprise server.Questions? Contact your Plotly representative.

Start Plotting Online!

Now you can convert your MATLAB® figures into beautiful, interactive, online graphs with fig2plotly(gcf);:

[X,Y,Z] = peaks;
contour(X,Y,Z,20);

fig2plotly(gcf, 'offline', false)
Click to copy

Note: fig2plotly(gcf); will render your plot using Plotly's own color and styling by default. To preserve your original MATLAB® color and styling, use: fig2plotly(gcf,'strip',false).

Learn more about using Plotly Offline for Matlab.

Response

Copy and paste the URL into your browser to see your graph!

url: 'https://plotly.com/~MATLABAPI/72'
message: [1x0 char]
warning: [1x0 char]
filename: 'untitled'
error: [1x0 char]
Click to copy

Credentials

The initialization step places a special .plotly/.credentials file in your home directory. Your ~/.plotly/.credentials file should look something like this:


{
"username": "DemoAccount",
"stream_ids": ["ylosqsyet5", "h2ct8btk1s", "oxz4fm883b"],
"api_key": "lr1c37zw81"
}
        
Click to copy

You can change the contents of this file manually or as described in the Initialization section.