1

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:enter image description here

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:enter image description here

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.

Community
  • 1
  • 1
user1913275
  • 73
  • 1
  • 1
  • 6
  • have you tried using `linkaxes`? – Max Oct 01 '15 at 11:17
  • Please provide a [mcve] so others can reproduce the behavior. In the meantime, check the `'ActivePositionProperty'` and see what it's set to, similar to the issues encountered in [this question](http://stackoverflow.com/questions/34384294). [`export_fig`](http://www.mathworks.com/matlabcentral/fileexchange/23629-export-fig) is a great external tool that may bypass the issue entierly. – sco1 Apr 19 '16 at 12:47
  • Check out https://stackoverflow.com/questions/36712491/multiple-y-axes-in-matlab-axis-alignment-issue-when-printing/36766754#36766754 – user1936752 Apr 21 '16 at 10:28

0 Answers0