GitHub - plotly/plotly_matlab: Plotly Graphing Library for MATLAB®
Repository navigation
plotly_matlabPublic
About
Plotly Graphing Library for MATLAB®
plot.ly/matlab/Topics
d3 d3js data-science data-visualization matlab plotly technical-computing webglResources
Readme MIT licenseCode of conduct
Code of conductContributing
Contributing Activity Custom propertiesStars
414 starsWatchers
63 watchingForks
166 forks Report repositoryBranches
Tags
Go to Branches page Go to Tags page
Latest commit
History
1,760 Commits
View commit history for this file.
Folders and files
Repository files navigation
Plotly Graphing Library for MATLAB® and GNU Octave
Create interactive, web-based charts in your browser from MATLAB® and GNU Octave.
MATLAB is a registered trademark of The MathWorks, Inc.
Features
- Convert native MATLAB and GNU Octave figures to interactive Plotly charts with a single line of code
- Fully offline: charts render locally in your browser -- plotly.js is downloaded once after installing and cached on your machine
- Publication-quality static export (PNG, JPEG, PDF, SVG) via the Kaleido runtime (downloaded once during setup)
- Comparison gallery generator (
makegallery) showing native and converted figures side by side
Install
MATLAB (R2021a or later)
-
Download
plotly_matlab-<version>.mltbxfrom the latest release . -
In MATLAB's file browser, double-click the file and follow the installer, or run:
matlab.addons.install('plotly_matlab-<version>.mltbx')The toolbox installs into your Add-Ons folder, and MATLAB adds it to the path.
-
Download plotly.js (needs an internet connection the first time):
getplotlyoffline()
GNU Octave, or MATLAB from source
Download the source (or clone the repository), then run from the extracted folder:
plotlysetup_offline() % adds plotly to the path and downloads plotly.js (requires internet once)
This adds plotly to the path for the current session and prints the addpath line to add to your ~/.octaverc (Octave) or startup.m (MATLAB) to keep it there.
Uninstall
- Toolbox:
matlab.addons.uninstall('Plotly Graphing Library for MATLAB') - Source: delete the folder and the
addpathline from your~/.octavercorstartup.m
The plotly.js bundle and any saved Plotly credentials are kept in a .plotly folder in your home folder (%APPDATA%\.plotly on Windows); delete it to remove them too.
Usage
Convert your MATLAB® or Octave figure into an interactive Plotly chart with a single line of code:
% Create some data for the two curves to be plotted
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
% Create a plot with 2 y axes using the plotyy function
figure;
[ax, h1, h2] = plotyy(x, y1, x, y2, 'plot');
% Add title and x axis label
xlabel('Time (s)');
title('Frequency Response');
% Use the axis handles to set the labels of the y axes
ylabel(ax(1), 'Low Frequency');
ylabel(ax(2), 'High Frequency');
%--PLOTLY--%
p = fig2plotly; % <-- converts the current figure to an interactive Plotly chart
The resulting figure is an interactive web chart: pan, zoom, hover, and download from the plotly.js toolbar.
Static export
Export figures to publication-quality static images:
p = fig2plotly; saveplotlyfig(p, 'testimage.svg') % PNG, JPEG, PDF, and SVG supported
Online mode
Offline usage is the default and requires nothing. For online features -- storing charts on the Plotly cloud, retrieving figures with getplotlyfig, and streaming -- configure your Plotly credentials:
saveplotlycredentials('your_username', 'your_api_key')
Retrieving figures
Fetch figures stored on the Plotly cloud:
p = getplotlyfig('chris', 1638) % downloads the graph data
Gallery
Generate a side-by-side comparison of native and converted figures for over 80 plot types:
makegallery('OutputFolder', 'gallery')
Documentation
- plotly.com/matlab - official documentation
Questions & troubleshooting
Ask on the Plotly Community Forum .
Contribute
Please do! This is an open source project. Check out the issues or open a PR!
We want to encourage a warm, welcoming, and safe environment for contributing to this project. See the code of conduct for more information.
The test suite (plotly/testing/runplotlytests.m) runs in both MATLAB and GNU Octave and is executed on every push via GitHub Actions.
License
MIT © Plotly, Inc.
About
Plotly Graphing Library for MATLAB®
plot.ly/matlab/