Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2ebc35b
plotly_version: 3.1.0, the latest release
robertoffmoura Nov 28, 2026
521293f
Add buildfile.m with a task that packages the toolbox
robertoffmoura Nov 28, 2026
3169b93
addtheme: find the themes next to addtheme.m
robertoffmoura Nov 28, 2026
5b77ffa
CI: package the toolbox and test-install it on R2021a and R2026a
robertoffmoura Nov 28, 2026
81312c6
buildfile: ship the LICENSE in the toolbox
robertoffmoura Nov 28, 2026
bfd5b58
CI: test-install the toolbox on R2026b too
robertoffmoura Nov 30, 2026
81d521d
CI: run the MATLAB tests on R2026b too
robertoffmoura Nov 30, 2026
9310178
CI: test-install the toolbox on Windows and macOS (R2026b)
robertoffmoura Nov 30, 2026
0ae9d92
CI: destroy the plotlyfig before uninstalling the toolbox
robertoffmoura Nov 30, 2026
427aa4a
addtheme: stop printing the theme's background colors
robertoffmoura Nov 30, 2026
c4ca85a
CI: update checkout, upload-artifact and download-artifact to their N…
robertoffmoura Nov 30, 2026
e969962
README: drop the Version line; plotly_version.m holds the version
robertoffmoura Nov 30, 2026
06231f3
CI: on a version tag, attach the tested toolbox to a draft release
robertoffmoura Nov 30, 2026
c8832fd
CONTRIBUTING: describe how to make a release
robertoffmoura Nov 30, 2026
0dc7da0
getplotlyoffline: default to the pinned plotly.js bundle
robertoffmoura Nov 30, 2026
609b9b0
getplotlyoffline: download with urlread in Octave, whose webread fails
robertoffmoura Nov 30, 2026
a44d463
README: install the toolbox, or from source in Octave; add uninstall …
robertoffmoura Nov 30, 2026
0f20316
Explain the draft release more plainly
robertoffmoura Nov 30, 2026
271198e
getplotlyoffline: point to saveplotlycredentials, which the toolbox i…
robertoffmoura Nov 30, 2026
9430803
buildfile: read git ls-files -z so unusual file names keep their paths
robertoffmoura Nov 30, 2026
5537c36
buildfile: print how many files go into the toolbox
robertoffmoura Nov 30, 2026
b61cc85
buildfile: say which file to fix when no version can be read
robertoffmoura Nov 30, 2026
19336fc
addtheme: report an unknown theme with error(), listing the valid names
robertoffmoura Nov 30, 2026
f0a6242
buildfile: list files with core.quotePath=false; MATLAB's system mang…
robertoffmoura Nov 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 114 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ name: CI
on:
push:
branches: [master, develop]
tags: ['[0-9]+.[0-9]+.[0-9]+']
pull_request:

jobs:
octave-tests:
runs-on: ubuntu-26.04
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v7

- name: Install Octave, Xvfb and packages
run: |
Expand All @@ -32,10 +33,10 @@ jobs:
strategy:
fail-fast: false
matrix:
release: [R2021a, R2022a, R2023a, R2024a, R2025a, R2026a]
release: [R2021a, R2022a, R2023a, R2024a, R2025a, R2026a, R2026b]
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v7

- name: Set up MATLAB
uses: matlab-actions/setup-matlab@v3
Expand All @@ -60,7 +61,116 @@ jobs:

- name: Upload gallery
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v7
with:
name: gallery-${{ matrix.release }}
path: gallery/

package-toolbox:
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v7

# the toolbox version comes from plotly_version.m, and File Exchange
# expects it to equal the release version
- name: Check the tag matches plotly_version.m
if: startsWith(github.ref, 'refs/tags/')
run: |
version=$(grep -oE '"[0-9]+\.[0-9]+\.[0-9]+"' plotly/plotly_aux/plotly_version.m | tr -d '"')
if [ "$version" != "$GITHUB_REF_NAME" ]; then
echo "::error::tag $GITHUB_REF_NAME does not match plotly_version.m ($version)"
exit 1
fi

# R2023a is the oldest release with matlab.addons.toolbox.ToolboxOptions
- name: Set up MATLAB
uses: matlab-actions/setup-matlab@v3
with:
release: R2023a
cache: true

- name: Package toolbox
uses: matlab-actions/run-command@v3
with:
command: buildtool package

- name: Upload toolbox
uses: actions/upload-artifact@v7
with:
name: toolbox
path: release/*.mltbx

install-toolbox:
name: install-toolbox (${{ matrix.os }}, ${{ matrix.release }})
needs: package-toolbox
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-24.04]
release: [R2021a, R2026a, R2026b]
include:
- os: windows-latest
release: R2026b
- os: macos-latest
release: R2026b
steps:
# no checkout: fig2plotly must come from the installed toolbox
- name: Download toolbox
uses: actions/download-artifact@v8
with:
name: toolbox
path: release

- name: Set up MATLAB
uses: matlab-actions/setup-matlab@v3
with:
release: ${{ matrix.release }}
cache: true

- name: Install, use and uninstall the toolbox
uses: matlab-actions/run-command@v3
with:
command: |
mltbx = dir(fullfile("release", "*.mltbx"));
assert(isscalar(mltbx), "expected one .mltbx in release/");
installed = matlab.addons.toolbox.installToolbox(fullfile(mltbx.folder, mltbx.name));
disp(installed);
location = which("fig2plotly");
assert(~isempty(location), "fig2plotly is not on the path after installing");
disp(location);
assert(isfile(fullfile(fileparts(location), "LICENSE")), "the toolbox has no LICENSE");
fig = figure("Visible", "off");
plot(1:3);
p = plotlyfig(fig, "visible", "off");
assert(numel(p.data) == 1, "plotlyfig converted %d traces, expected 1", numel(p.data));
addtheme(struct("layout", struct()), "ggplot2");
clear p; % plotlyfig's destructor must run while the toolbox is still installed
close(fig);
matlab.addons.toolbox.uninstallToolbox(installed);
assert(isempty(which("fig2plotly")), "fig2plotly is still on the path after uninstalling");

# Creates a draft with the .mltbx attached; a maintainer publishes it, so
# services that react to published releases see it complete.
release:
if: startsWith(github.ref, 'refs/tags/')
needs: [octave-tests, matlab-tests, install-toolbox]
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
# the exact .mltbx the install jobs tested
- name: Download toolbox
uses: actions/download-artifact@v8
with:
name: toolbox
path: release

- name: Create draft release
env:
GH_TOKEN: ${{ github.token }}
run: >-
gh release create "$GITHUB_REF_NAME" release/*.mltbx
--repo "$GITHUB_REPOSITORY" --verify-tag --draft
--title "$GITHUB_REF_NAME" --generate-notes
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dev/
*.asv
untitled.html
release/
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,29 @@ makegallery('Functions', {'myplot'}, 'Open', false)
```

Keep commits to one logical change with a short imperative message.

## Releasing

Releases are made from `master` by pushing a version tag. CI then tests the
toolbox (`.mltbx`) and attaches it to a draft GitHub release.

1. Set the new version in `plotly/plotly_aux/plotly_version.m` (for example
`"3.2.0"`) and merge that change into `master`. This file is the only place
the version is kept; the toolbox takes its version from it.
2. Tag the merged commit with the plain version (no `v` prefix) and push the
tag:

```bash
git tag 3.2.0
git push origin 3.2.0
```

CI checks that the tag matches `plotly_version.m`, runs all the tests,
installs the packaged toolbox on Linux, Windows and macOS, and then creates
a draft release with `plotly_matlab-<version>.mltbx` attached and release
notes generated from the merged pull requests.
3. Review the draft on the repository's Releases page and click **Publish**.

If CI fails, nothing has been published yet. Delete the draft if there is one,
delete the tag (`git push --delete origin 3.2.0` and `git tag -d 3.2.0`), fix
the problem, and tag again.
37 changes: 28 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,49 @@
</a>
</div>

Version: 3.1.0

*MATLAB is a registered trademark of The MathWorks, Inc.*

## Features

- Convert native MATLAB and GNU Octave figures to interactive [Plotly](https://plotly.com) charts with a single line of code
- Fully offline: charts render locally in your browser — plotly.js is downloaded once during setup and cached on your machine
- 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

Download the latest version of the wrapper:
### MATLAB (R2021a or later)

1. Download `plotly_matlab-<version>.mltbx` from the [latest release](https://github.com/plotly/plotly_matlab/releases/latest).
2. In MATLAB's file browser, double-click the file and follow the installer, or run:

```matlab
matlab.addons.install('plotly_matlab-<version>.mltbx')
```

The toolbox installs into your Add-Ons folder, and MATLAB adds it to the path.
3. Download plotly.js (needs an internet connection the first time):

- [github.com/plotly/plotly_matlab/archive/master.zip](https://github.com/plotly/plotly_matlab/archive/master.zip)
```matlab
getplotlyoffline()
```

Then, from the extracted folder, run:
### GNU Octave, or MATLAB from source

Download the [source](https://github.com/plotly/plotly_matlab/archive/master.zip) (or clone the repository), then run from the extracted folder:

```matlab
plotlysetup_offline() % one-time setup: downloads and caches plotly.js for offline usage (requires internet once)
plotlysetup_offline() % adds plotly to the path and downloads plotly.js (requires internet once)
```

This works in both MATLAB and GNU Octave.
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 `addpath` line from your `~/.octaverc` or `startup.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

Expand Down Expand Up @@ -80,7 +99,7 @@ saveplotlyfig(p, 'testimage.svg') % PNG, JPEG, PDF, and SVG supported
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:

```matlab
plotlysetup_online('your_username', 'your_api_key')
saveplotlycredentials('your_username', 'your_api_key')
```

## Retrieving figures
Expand Down
60 changes: 60 additions & 0 deletions buildfile.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function plan = buildfile
plan = buildplan(localfunctions);
end

function packageTask(~)
% Package the plotly folder as a toolbox in release/
root = fileparts(mfilename('fullpath'));

% only tracked files: a working copy also holds downloads such as the
% Kaleido binaries under plotly/kaleido; core.quotePath=false keeps
% names with non-ASCII characters unquoted
[status, listing] = system(sprintf('git -C "%s" -c core.quotePath=false ls-files plotly', root));
if status ~= 0
error('buildfile:git', 'git ls-files failed:\n%s', listing);
end
files = string(splitlines(strtrim(listing)));
missing = files(~isfile(root + "/" + files));
if ~isempty(missing)
error('buildfile:missingFiles', 'git ls-files listed files that do not exist:\n%s', ...
strjoin(missing, newline));
end
files = files(~startsWith(files, "plotly/testing/") & ~contains(files, "/Test_"));
folders = unique(regexprep(files(endsWith(files, ".m")), '/[^/]*$', ''));

version = regexp(fileread(fullfile(root, 'plotly', 'plotly_aux', 'plotly_version.m')), ...
'"(\d+\.\d+\.\d+)"', 'tokens', 'once');
if isempty(version)
error('buildfile:version', ...
'could not read a version like "1.2.3" from plotly/plotly_aux/plotly_version.m');
end
version = string(version{1});

% ship the license at the toolbox root; the copy only lives for the build
licenseCopy = fullfile(root, 'plotly', 'LICENSE');
copyfile(fullfile(root, 'LICENSE'), licenseCopy);
removeLicense = onCleanup(@() delete(licenseCopy)); %#ok<NASGU>

opts = matlab.addons.toolbox.ToolboxOptions(fullfile(root, 'plotly'), ...
"e59f316c-4a80-11e4-9553-005056977bd0");
opts.ToolboxName = "Plotly Graphing Library for MATLAB";
opts.ToolboxVersion = version;
opts.Summary = "Convert MATLAB figures into interactive plotly.js charts";
if isprop(opts, 'Description') % removed in R2026b
opts.Description = "fig2plotly converts MATLAB figures into interactive " + ...
"plotly.js web charts that open in your browser, fully offline. " + ...
"Run getplotlyoffline() once after installing to download plotly.js.";
end
opts.AuthorCompany = "Plotly";
opts.ToolboxFiles = [root + "/" + files; string(licenseCopy)];
opts.ToolboxMatlabPath = root + "/" + folders;
opts.MinimumMatlabRelease = "R2021a";
opts.MaximumMatlabRelease = "";
opts.OutputFile = fullfile(root, "release", "plotly_matlab-" + version + ".mltbx");

if ~isfolder(fullfile(root, "release"))
mkdir(fullfile(root, "release"));
end
fprintf('Packaging %d files into %s\n', numel(opts.ToolboxFiles), opts.OutputFile);
matlab.addons.toolbox.packageToolbox(opts);
end
17 changes: 17 additions & 0 deletions plotly/Test_plotlysetup.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ function testPrintPlotlyPathHint(tc)
tc.verifyTrue(~isempty(strfind(output, ...
'addpath(genpath(''/opt/it''''s here/plotly''));')), output);
end

function testGetPlotlyOfflineDownloadsBundle(tc)
if isempty(getenv('CI'))
return % downloads plotly.js from the CDN
end
sandbox = Test_plotlysetup.enterSetupSandbox(); %#ok<NASGU>
if ~strcmp(getuserdir(), getenv('HOME'))
return % getuserdir() is outside the sandbox, so this would replace the real bundle.
end

evalc('getplotlyoffline()');

bundle = fileread(fullfile(getenv('HOME'), '.plotly', 'plotlyjs', ...
'plotly-matlab-offline-bundle.js'));
tc.verifyTrue(~isempty(strfind(bundle(1:min(end, 100)), 'plotly.js v2.35.3')), ...
'the saved bundle does not start with the plotly.js 2.35.3 header');
end
end

methods (Static)
Expand Down
39 changes: 7 additions & 32 deletions plotly/addtheme.m
Original file line number Diff line number Diff line change
@@ -1,50 +1,25 @@
function f = addtheme(f, theme)
%-validate theme name-%

themePath = 'plotly/themes';
S = dir(themePath);

if isempty(S)
paths = split(path, ':');
for p = 1:length(paths)
if ~isempty(strfind(paths{p}, themePath))
themePath = paths{p};
break;
end
end
S = dir(themePath);
end
themePath = fullfile(fileparts(mfilename('fullpath')), 'themes');
S = dir(fullfile(themePath, '*.json'));

N = {S.name};

if ~any(strcmp(N,strcat(theme, '.json'))) == 1
ME = MException('MyComponent:noSuchVariable', ...
[strcat('\n<strong>', theme, ...
'</strong> is not a supported themes.'), ...
' Please choose one of these theme names:\n\n', ...
strrep(strrep([S.name], '...', ''), '.json', ' | ')]);
throw(ME)
if ~any(strcmp(N, strcat(theme, '.json')))
error('addtheme:unknownTheme', ...
'%s is not a supported theme. Choose one of: %s', ...
theme, strjoin(strrep(N, '.json', ''), ' | '));
end

%-add theme to figure-%

fname = sprintf('%s/%s.json', themePath, theme);
% fname = strcat('plotly/themes/', theme, '.json');
fname = fullfile(themePath, sprintf('%s.json', theme));
fid = fopen(fname);
raw = fread(fid,inf);
str = char(raw');
fclose(fid);
theme_template = jsondecode(str);

f.layout.template = theme_template;

if isfield(f.layout.template.layout, 'paper_bgcolor')
disp(strcat('layout.bg_paper:::',...
f.layout.template.layout.paper_bgcolor))
end

if isfield(f.layout.template.layout, 'plot_bgcolor')
disp(strcat('layout.plot_bgcolor:::',...
f.layout.template.layout.plot_bgcolor))
end
end
2 changes: 1 addition & 1 deletion plotly/plotly_aux/plotly_version.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function version = plotly_version()
version = "3.0.0";
version = "3.1.0";
end
Loading
Loading