Plotly Graphing Library for MATLAB

repository·master·Indexed 19 days ago

https://github.com/plotly/plotly_matlab

A wrapper that allows MATLAB users to convert standard MATLAB figures into interactive, web-based Plotly charts. It supports offline and online modes, featuring functions such as fig2plotly for figure conversion, saveplotlyfig for exporting to static images (PNG, PDF, SVG, JPEG), and plotlystream for real-time data streaming.

Tokens
1.2K
Snippets
5
Records
7
Agent score
15%

What's inside plotly_matlab

  1. Install and set up Plotly for MATLAB

    master

    To use Plotly from your MATLAB desktop environment, follow these steps:

    1. Sign up: Create a Plotly account online or use the signup.m script provided in the library.
    2. Configure credentials: Run plotlysetup with your Plotly username and API key to link your MATLAB environment to your account.
    3. Convert figures: Use fig2plotly to convert existing MATLAB figures into interactive Plotly graphs.

    Once converted, you can view, style, and share your plots in your web browser at https://plot.ly.

    >> plotlysetup('username','api_key')
    >> fig2plotly(fig)
  2. Install the Plotly MATLAB wrapper

    master

    To use Plotly with MATLAB, download the latest version of the wrapper from the GitHub master zip. Installation depends on whether you want to use Plotly offline or online.

    Offline Installation

    Use plotlysetup_offline() for standard offline use. If you have a specific Plotly bundle URL (e.g., http://cdn.plot.ly/plotly-latest.min.js), pass it as an argument:

    plotlysetup_offline('http://cdn.plot.ly/plotly-latest.min.js')

    Online Installation

    For online use, use plotlysetup_online() with your Plotly credentials:

    plotlysetup_online('your_username', 'your_api_key')
    plotlysetup_offline()
    % or
    plotlysetup_online('your_username', 'your_api_key')
  3. Typical Plotly-MATLAB workflow

    master

    The standard workflow for generating publication-quality interactive graphs is as follows:

    1. Data Generation: Collect or generate data within your MATLAB environment.
    2. Upload: Send the data to your Plotly account using the Plotly-MATLAB API.
    3. Interactive Viewing: View the interactive graph in your browser.
    4. Styling: Use the Plotly GUI in your browser to customize the graph appearance.
    5. Sharing: Share the graph via shortlinks, Facebook, or Twitter.
    6. Exporting: Export the final styled graph to high-quality formats like PNG, PDF, EPS, or SVG.
  4. Convert MATLAB figures to Plotly graphs with fig2plotly

    master

    You can convert existing MATLAB figures into interactive Plotly graphs using the fig2plotly function. This function takes a standard MATLAB figure handle and converts its properties into a Plotly-compatible format.

    Example workflow:

    1. Create a standard MATLAB plot (e.g., using plot, plotyy, etc.).
    2. Call p = fig2plotly; to perform the conversion.
    % 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
     ax(1).YLabel.String = "Low Frequency";
     ax(2).YLabel.String = "High Frequency";
    
     %--PLOTLY--%
     p = fig2plotly; % <-- converts the yy-plot to an interactive, online version.
  5. Use new Plotly MATLAB features

    master

    The Plotly MATLAB API includes several advanced functions for managing your workflow:

    • plotlyupdate: Automatically updates the Plotly API MATLAB libraries in your MATLAB search path to match the latest release.
    • getplotlyfig('username','figure_id'): Retrieves the data and layout information from any publicly available graph online.
    • saveplotlyfig(figure,'image_name','ext'): Converts a Plotly figure into a high-quality static image. Supported extensions (ext) include png, pdf, svg, and jpeg.
    • plotlystream: Streams your data directly from MATLAB to your Plotly account in real-time.