I have a dataset with date/time along the x axis, and concentration on the first y axis, but would like to show the equivalent value in a different measure of concentration on a second y axis (like having cm on one y axis and inches on the other).
I used gnovice's solution from here to add the extra axis: Different right and left axes in a MATLAB plot?
It works beautifully for me on the screen:
But when I "print" to PDF using
print(gcf,'-dpdf',[filename '.pdf'])
The lower end of the axis moves so that the two ranges are no longer equivalent:
Is there a way to glue the additional axis in place when I generate the PDF? The bare bones of my code for this plot are below:
subplot(6,1,4),
H3 = scatter(sampletime,SSCcoarse,'g<','filled')
hold on
H4 = scatter(sampletime,(SSCcoarse+SSCfine),'g<')
ylim([0 0.08])
set(gca,'ytick',[0:0.04:0.08],'yticklabel',['0.00';'0.04';'0.08'])
ylabel('SSC (g L^{-1})')
xlim([startdate enddate])
datetick('x','dd-mmm','keeplimits')
% Add data from extra site on original axis
H5 = scatter(sampletime2,SSCcoarse2,'r<','filled')
H6 = scatter(sampletime2,(SSCcoarse2+SSCfine2),'r<')
%% Add equivalent turbidity y axis
axesPosition = get(gca,'Position'); %# Get the current axes position
hNewAxes = axes('Position',axesPosition,... %# Place a new axes on top...
'Color','none',... %# ... with no background color
'YLim',[0 0.08*190.6752],... %# ... and a different scale
'YAxisLocation','right',... %# ... located on the right
'XTick',[],... %# ... with no x tick marks
'YTick',[0:5:15],'YTickLabel',['0 ';'5 ';'10';'15'],...
'Box','off'); %# ... and no surrounding box
ylabel(hNewAxes,'Equivalent turbidity (FNU)'); %# Add a label to the right y axis
%% Filename and save
filename = 'filename';
fillPage(gcf, 'margins', [0 0 0 0], 'papersize', [11 38]);
print(gcf,'-dpdf',[filename '.pdf'])
Any help would be much appreciated. I don't know if the problem is in the code for the graph or in the code to "print". Thank you.