dennischancs / plotly_matlab

Plotly Graphing Library for MATLAB®

Home Page:https://plot.ly/matlab/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enhanced and fix bugs for plotly/plotly_matlab

Now, plotly_matlab can use latest plotly.min.js with plotly for python, and convert to html with smaller file size than before by nbconvert.

  • plotlyoffline.m
    • fix: Escaped character '\s' is not valid. See 'doc sprintf'.
    • fix: CJK garbled character on image.
    • enhance: use plotly.min.js from plotly.py which keep latest version( 2022-03-11 is v2.9.0) with new features.
  • new plotlyoffline2.m
    • enhance: shrink ipynb file size. Thanks to the motheds from plotly.py.
      • Generate offline Plotly figure with three layers for better compatibility as ipynb file inserted cell. Three layers: "application/vnd.plotly.v1+json": {json_compatible_fig_dict}, "image/png":"base64" and "text/html":"plotly_fig_html". Need install [dennischancs/plotly_matlab]https://github.com/dennischancs/imatlab/tree/dennischancs-patch-1)
  • write_image.m
    • fix: when input nargin < 4, the output figure without an extension.
    • enhance: write static image from matlab_figure_handle gcf directly.
  • fix: figure title has more html tag </b> or <\/b> use the command below. And the incomplete tag <b> also work well. see Issue #474 · plotly/plotly_matlab.
    sed -i 's#</b>##g' `find /plotly_matlab_toolbox_path/plotly/plotlyfig_aux -name "*.m"`
  • new write_html.m
    • enhance: add a New Fuction to write plotly figure to single html file offline and return the html path , usage: html = write_html(gcf, 'test.html').
    • Deprecated: resp = fig2plotly(gcf,'filename',filename,'offline',1,'strip',0,'open',0); resp.url.

Usage

  1. pip install plotly && pip install -U kaleido. see plotly/plotly.py

    • plotly_matlab is a tool for convert matlab fig to plotly image.
    • kaleido is a tool for convert plotly image to static image(png/jpg/webp, svg/pdf).
  2. download this master and add to matlab search path

    • git clone --depth=1 https://github.com/dennischancs/plotly_matlab
    • start matlab, and run addpath(genpath('your_plotly_matlab_path'));, then savepath.
  3. install dennischancs/imatlab kernel for jupyterlab to use matlab

    • imatlab/imatlab is a jupyter kernel for matlab and have a imatlab_export_fig function to quick use plotly_matlab convert fig to plotly.
    • imatlab v0.4 cannot display CJK character correctly in stdout, the solution see dennischancs/imatlab.

Examples 1: convert matlab fig to plotly image

imatlab_export_fig('fig2plotly') % fig2plotly 建议放到代码最前面
X = linspace(0,2*pi,50)';
Y = [cos(X), 0.5*sin(X)];
stem(X,Y);
title('测试fig2plotly');

测试fig2plotly结果

Examples 2: convert plotly image to static image

imatlab_export_fig('fig2plotly') % fig2plotly 建议放到代码最前面
X = linspace(0,2*pi,50)';
Y = [cos(X), 0.5*sin(X)];
%fid = figure(); % 没有指定figure句柄,则用系统默认变量gcf
stem(X,Y);
title('测试fig2plotly');

% 创建图像目录
folder = 'images-matlab';
if ~exist(folder,'dir')
    mkdir(folder);
end

filename = [folder, '/', '测试fig2plotly'];
write_image(gcf, 'svg', filename);

plotly导出静态图像 测试plotly导出静态图像结果


Plotly Graphing Library for MATLAB®

Plotly Graphing Library for MATLAB® - Create interactive charts in your web browser with MATLAB® and Plotly

Version: 2.2.10

MATLAB is a registered trademarks of The MathWorks, Inc.

Install

The latest version of the wrapper can be downloaded here.

Once downloaded, run plotlysetup_offline() to get started If you have a plotly bundle url of the form 'http://cdn.plot.ly/plotly-latest.min.js', then run instead `plotlysetup_offline('plotly_bundle_url')

For online use, run plotlysetup_online('your_username', 'your_api_key') to get started.

Updates

NOTE: plotlyupdate.m is currently turned off.

Please manually download and setup the latest version of the wrapper by following the installation instructions above.

Usage

Convert your MATLAB® figures into online Plotly graphs 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
 set(get(ax(1), 'Ylabel'), 'String', 'Low Frequency');
 set(get(ax(2), 'Ylabel'), 'String', 'High Frequency');

 %--PLOTLY--%
 p = fig2plotly; % <-- converts the yy-plot to an interactive, online version.

 %--URL--%
 % p.url = 'https://plot.ly/~matlab_user_guide/1522'

MATLAB® Contour Plot

Also, access other Plotly services and graphs programatically. Like, publication-quality image export:

 saveplotlyfig(p, 'testimage.svg')

and Plotly figure retrieval:

 p = getplotlyfig('chris', 1638) % downloads the graph data from https://plot.ly/~chris/1638

Documentation

This lives here: https://plot.ly/matlab

Questions & troubleshooting

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.

License

MIT © 2021 Plotly, Inc.

About

Plotly Graphing Library for MATLAB®

https://plot.ly/matlab/

License:MIT License


Languages

Language:MATLAB 100.0%Language:M 0.0%