Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Plotyy with trend lines

Asked by Bahram on 23 Apr 2012

Hi,

I am trying to plot two sets of data on two different y axes, and also plot the trend lines for both sets of data.

Here are the data sets:

x axis                                  date_x_axis
y-axis 1                              strain(1:end,1)
y-axis 2                              temperature(1:end,1)
trend line for y-axis 1         strain_trend
trend line for y-axis 12       temp_trend

I've used the following code.

figure1=figure ('Name','G01 & Temp.');
hold('on')
%Actual data
[AX,H1,H2] = plotyy(date_x_axis,strain(1:end,1),date_x_axis,temperature(1:end,1));
grid('on')
set(gca,'GridLineStyle','--','LineWidth',1)
set(gca,'XMinorTick','on')
set(H1,'Color','black')
set(H2,'Color','red')
set(H1,'Linewidth',1)
set(H2,'Linewidth',1)
set(AX,{'ycolor'},{'black';'black'})
set(AX,'Fontsize',fontsize_axis)
set(AX,'FontName',fontname)
set(get(AX(1),'Ylabel'),'String','Strain (\mu strain)','Fontsize',...
    fontsize_label,'Fontname',fontname)
set(get(AX(2),'Ylabel'),'String','Temperature (oF)','Fontsize',...
    fontsize_label,'Fontname',fontname)
xlabel('DATE')
title('G01')
legend(AX(1),'Strain','Temperature','Location','Best')
datetick(AX(1),'x','mm/dd/yy')
datetick(AX(2),'x','mm/dd/yy')
%Trend lines
[AXX,H3,H4] = plotyy(date_x_axis,strain_trend,date_x_axis,temp_trend);
set(H3,'Color','black')
set(H4,'Color','red')
set(H3,'Linewidth',1.1)
set(H4,'Linewidth',1.1)
set(AXX,{'ycolor'},{'black';'black'})
datetick(AXX(1),'x','mm/dd/yy')
datetick(AXX(2),'x','mm/dd/yy')

The trend line plots put numbers on the axes, and these numbers mess things up. Could you tell me how I can add the trend lines without plotting axes?

Thanks for your time.

1 Comment

Oleg Komarov on 23 Apr 2012

Please, format your question as shown here: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup

Bahram

Tags

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson on 24 Apr 2012

I do not recommend using two plotyy() calls for the same area (with "hold on"). I recommend instead using plotyy() once, and then taking the two axes returned and plot() or line() appropriately against each of those axes.

0 Comments

Walter Roberson

Contact us