Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
2002 3169 9.0; 2003 3227 9.0; 2004 2989 8.2; 2005 2903 7.9;
2006 2779 7.4; 2007 2725 7.2];
years = TBdata(:,1);
cases = TBdata(:,2);
rate = TBdata(:,3);
% Create a plot with 2 y axes using the plotyy function
% Cases are represented by a bar chart ; Infection rate is represented by an xy plot
figure;
[ax, h1, h2] = plotyy(years, cases, years, rate, 'bar', 'plot');
% Change the bar colors to light gray
set(h1, 'FaceColor', [0.8, 0.8, 0.8]);
% Chnage the thickness of the line
set(h2, 'LineWidth', 2);
% Add title and x axis label
title('Tuberculosis Cases: 1991-2007');
xlabel('Years');
% Use the axis handles to set the labels of the y axes
set(get(ax(1), 'Ylabel'), 'String', 'Cases');
set(get(ax(2), 'Ylabel'), 'String', 'Infection rate in cases per thousand');
% PLOTLY
response = fig2plotly();
plotly_url = response.url;
xf = 2;
%sampling rate
fs = 1000;
%independent variable x
x = linspace(x0,xf,fs);
sig1 = abs(sin(x).*exp(x));
sig1log = log(sig1);
%create a figure object
fig = figure('Color','w');
%plotyy
[ax, s1h1 s1h2] = plotyy(x,sig1,x,sig1,'plot','semilogy');
%sig1 color
sig1col = [0 200 90]/255;
%sig1log color
sig1logcol = [210 30 50]/255;
%style the plot
set(s1h1,'Color',sig1col,'LineWidth',5);
set(s1h2,'Color',sig1logcol,'LineWidth',5);
set(ax(1),'YColor',sig1col);
set(ax(2),'YColor',sig1logcol);
%x-axis and y-axis labels
xlabel('$x$','Interpreter','latex');
set(get(ax(1),'Ylabel'),'String','$\mbox{y (linear)}$','Interpreter','latex')
set(get(ax(2),'Ylabel'),'String','$\mbox{y (log)}$','Interpreter','latex')
%add annaotation
text(-1,5,'$y = |sin(x)e^{x}|$','Interpreter','latex');
%add legend
leg = legend('$\mbox{y(linear)}$ ','$\mbox{y(log)}$ ', 'Location', 'NorthWest');
set(leg,'Interpreter','latex');
%grid
grid on
% PLOTLY
response = fig2plotly(fig);
plotly_url = response.url;
Two Y-Axes
% Fill in with your personal username and API key
% or, use this public demo account
signin('MATLAB-Demo-Account', 'p42phiifti')
trace1 = struct(...
'x', [1, 2, 3], ...
'y', [40, 50, 60], ...
'name', 'yaxis data', ...
'type', 'scatter');
trace2 = struct(...
'x', [2, 3, 4], ...
'y', [4, 5, 6], ...
'name', 'yaxis2 data', ...
'yaxis', 'y2', ...
'type', 'scatter');
data = {trace1, trace2};
layout = struct(...
'title', 'Double Y Axis Example', ...
'yaxis', struct('title', 'yaxis title'), ...
'yaxis2', struct(...
'title', 'yaxis2 title', ...
'titlefont', struct('color', 'rgb(148, 103, 189)'), ...
'tickfont', struct('color', 'rgb(148, 103, 189)'), ...
'overlaying', 'y', ...
'side', 'right'));
response = plotly(data, struct('layout', layout, 'filename', 'multiple-axes-double', 'fileopt', 'overwrite'));
plot_url = response.url
Multiple Y-Axes
% Fill in with your personal username and API key
% or, use this public demo account
signin('MATLAB-Demo-Account', 'p42phiifti')
trace1 = struct(...
'x', [1, 2, 3], ...
'y', [4, 5, 6], ...
'name', 'yaxis1 data', ...
'type', 'scatter');
trace2 = struct(...
'x', [2, 3, 4], ...
'y', [40, 50, 60], ...
'name', 'yaxis2 data', ...
'yaxis', 'y2', ...
'type', 'scatter');
trace3 = struct(...
'x', [4, 5, 6], ...
'y', [40000, 50000, 60000], ...
'name', 'yaxis3 data', ...
'yaxis', 'y3', ...
'type', 'scatter');
trace4 = struct(...
'x', [5, 6, 7], ...
'y', [400000, 500000, 600000], ...
'name', 'yaxis4 data', ...
'yaxis', 'y4', ...
'type', 'scatter');
data = {trace1, trace2, trace3, trace4};
layout = struct(...
'title', 'multiple y-axes example', ...
'width', 800, ...
'xaxis', struct('domain', [0.3, 0.7]), ...
'yaxis', struct(...
'title', 'yaxis title', ...
'titlefont', struct('color', '#1f77b4'), ...
'tickfont', struct('color', '#1f77b4')), ...
'yaxis2', struct(...
'title', 'yaxis2 title', ...
'titlefont', struct('color', '#ff7f0e'), ...
'tickfont', struct('color', '#ff7f0e'), ...
'anchor', 'free', ...
'overlaying', 'y', ...
'side', 'left', ...
'position', 0.15), ...
'yaxis3', struct(...