✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.

MATLAB figure reference


The pages linked in the sidebar together form the exhaustive reference for all of the attributes in the core figure data structure that the plotly library operates on. They are automatically-generated from the machine-readable Plotly.js schema reference.

How are Plotly attributes organized?

fig2plotly converts MATLAB figures to online Plotly graphs. MATLAB describes figures differently than Plotly. Plotly's MATLAB library crawls the MATLAB figure objects and translates the MATLAB attributes into the structure that Plotly uses to describe and draw data visualizations.

You may wish to customize the figure after you have translated it but before you have sent it to Plotly. You can customize every attribute of a plotly graph: the hover text, the colorscales, the gridlines, the histogram binning, etc.

plotly charts are described declaratively with struct and cell array objects. This page contains an extensive list of the keys used to describe plotly graphs inside these struct objects. Here is a simple example of how to translate a MATLAB figure, modify some attributes, and then send it to Plotly.

>> x = linspace(-2*pi, 2*pi);
    >> y1 = sin(x);
    >> y2 = cos(x);
    >> plot(x, y1, x, y2);

    %% Translate the figure from MATLAB to Plotly
    >> fig = plotlyfig(gcf);

    >> fig.PlotOptions.Strip = 0; % If 0, don't strip MATLAB's styling in translation. If 1, strip MATLAB's styling.

    >> fig.data
    ans =

       [1x1 struct]    [1x1 struct]

    >> fig.data{1}    % The 'type' of this trace is 'scatter'. scatter's reference: #scatter
    ans =

            xaxis: 'x1'             % more about scatter's 'xaxis': #scatter-xaxis
            yaxis: 'y1'             % scatter's 'yaxis' property:   #scatter-yaxis
             type: 'scatter'
          visible: 1                % scatter's 'visible' property: #scatter-visible
                x: [1x100 double]   % scatter's 'x' property:       #scatter-x
                y: [1x100 double]   % scatter's 'y' property:       #scatter-y
             name: ''               % scatter's 'name' property:    #scatter-name
             mode: 'lines'          % scatter's 'mode' property:    #scatter-mode
             line: [1x1 struct]     % scatter's 'line' property:    #scatter-line
           marker: [1x1 struct]     % scatter's 'marker' property:  #scatter-marker
       showlegend: 1                % scatter's 'showlegend':       #scatter-marker

    %% Modify or add new properties to this trace
    >> fig.data{1}.name = 'Current'; % Update the legend name to 'Current'

    >> fig.layout     % layout reference: #layout
    ans =

            autosize: 0                     % layout's 'autosize':      #layout-autosize
              margin: [1x1 struct]          % layout's 'margin':        #layout-margin
          showlegend: 0                     % layout's 'showlegend':    #layout-showlegend
               width: 840                   % layout's 'width':         #layout-width
              height: 630                   % layout's 'height':        #layout-height
       paper_bgcolor: 'rgb(255,255,255)'    % layout's 'paper_bgcolor': #layout-paper_bgcolor
           hovermode: 'closest'             % layout's 'hovermode':     #layout-hovermode
        plot_bgcolor: 'rgba(0,0,0,0)'       % layout's 'plot_bgcolor':  #layout-plot_bgcolor
              xaxis1: [1x1 struct]          % layout's 'xaxis':         #layout-xaxis
              yaxis1: [1x1 struct]          % layout's 'yaxis':         #layout-yaxis
         annotations: {[1x1 struct]}        % layout's 'annotations':   #layout-annotations

    >> fig.layout.showlegend = true;  % layout's 'showlegend':    #layout-showlegend
    >> fig.layout.legend = struct('x', 1, 'y', 1); % Update the legend: #layout-legend
    >> fig.layout.title = 'Modified plot';

    %% Set the filename, and overwrite the plot if it already exists
    >> fig.PlotOptions.FileName = 'Customized plot';
    >> fig.PlotOptions.FileOpt = 'overwrite';
    >> % using offline? Then set fig.PlotOptions.Offline = true;

    %% Send to plotly
    >> fig.plotly