Controlling Grids and axes in dual axis plots
1 view (last 30 days)
Show older comments
This is a continuation of the question I asked earlier: http://www.mathworks.com/matlabcentral/answers/68730-controlling-dual-axis-plots
In the accepted solution for this problem, Kelly Kearney proposed a method to plot the dual axis using plotyy. Using the answer I was able to indeed plot the figures. However, there has been some issues involving the axes and legend that I might need help on.
Below is the code I used, modified from last suggestion, and abbreviated.
[ax,ln1,ln2]=plotyy(straininst,stressinst.*1e-6,e_piezo,cap);
set(get(ax(1),'Ylabel'),'String','Stress(MPa)');
grid on
set(ln1,'Color','b');
set(ln2,'Color','r');
hold(ax(1),'on');
handle=plot(ax(1),strainamp,stressamp.*1e-6,'c',strainamp(n1:n2),...
stressamp(n1:n2).*1e-6,'y',e_amp14,-s_amp14.*1e-6...'--rs');
hold(ax(2),'on');
plot(ax(2),e_cap14,cap14,'Color','m');
legend([handle;ln1;ln2],{'E_{sg12}','E_{sg12slope}',...
,'piezo12','piezo14'});
set(get(ax(2),'Ylabel'),'String','cap');
As it is shown, the axis, for some reason, depends on the axis on the right, and also the grid. In addition, if I plot more data values to this graph, I notice that data parts are being cut off because of some "hard axis settings" that gets applied for some reason.
Attached in the picture where I put a lot more data points, and it is causing cutoffs in data as well as missing legend entries.
any help will be appreciated. Thanks!

Answers (0)
See Also
Categories
Find more on Two y-axis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!