Show Sidebar Hide Sidebar

Setting the Title, Legend Entries, and Axis Titles in MATLAB

How to set the title, legend-entries, and axis-titles in MATLAB.

% Learn about API authentication here: https://plot.ly/matlab/getting-started
% Find your api_key here: https://plot.ly/settings/api

x = randi([0 100],1,100);
y = randi([0 100],1,100);
fig = figure;
plot(x,y,'bo');
title('Custom Title','FontSize',24,'Color','g','FontName','FixedWidth');

resp = fig2plotly(fig,'strip',false);
plotly_url = resp.url;
% Learn about API authentication here: https://plot.ly/matlab/getting-started
% Find your api_key here: https://plot.ly/settings/api

trace1 = struct(...
  'x', [0, 1, 2, 3, 4, 5, 6, 7, 8], ...
  'y', [0, 1, 2, 3, 4, 5, 6, 7, 8], ...
  'name', 'Name of Trace 1', ...
  'type', 'scatter');
trace2 = struct(...
  'x', [0, 1, 2, 3, 4, 5, 6, 7, 8], ...
  'y', [1, 0, 3, 2, 5, 4, 7, 6, 8], ...
  'name', 'Name of Trace 2', ...
  'type', 'scatter');
data = {trace1, trace2};
layout = struct(...
    'title', 'Plot Title', ...
    'xaxis', struct(...
      'title', 'x Axis', ...
      'titlefont', struct(...
        'family', 'Courier New, monospace', ...
        'size', 18, ...
        'color', '#7f7f7f')), ...
    'yaxis', struct(...
      'title', 'y Axis', ...
      'titlefont', struct(...
        'family', 'Courier New, monospace', ...
        'size', 18, ...
        'color', '#7f7f7f')));
response = plotly(data, struct('layout', layout, 'filename', 'styling-names', 'fileopt', 'overwrite'));
plot_url = response.url
% Learn about API authentication here: https://plot.ly/matlab/getting-started
% Find your api_key here: https://plot.ly/settings/api

plot(rand(4))
h_legend=legend('One','Two','Three','Four');
title('Plot with Custom Legend');

% Convert fig to plotly..
response = fig2plotly;

% Add customization to legend..
response.layout.legend.x = 1.5;
response.layout.legend.y = 0.5;
response.layout.legend.borderwidth = 1;
response.layout.legend.bgcolor = 'rgb(217,217,2117)';

% Send data to plotly..
response2 = plotly(response.data, struct('layout',response.layout));
plotly_url = response2.url;
% Learn about API authentication here: https://plot.ly/matlab/getting-started
% Find your api_key here: https://plot.ly/settings/api

x = randi([0 100],1,100);
y = randi([0 100],1,100);
fig = figure;
plot(x,y,'bo');
title('Custom Axis Labels');
xlabel('X Label','FontSize',20,'Color','b','Position',[50 -10]);
ylabel('Y Label','FontSize',20,'Color','r','Position',[-10 50] );

resp = fig2plotly(fig,'strip',false);
plotly_url = resp.url;
Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to a Developer Support Plan.