Matlab: Add additional y axis (linearly scaled to original) and “print” to PDF without losing axis alignment

假如想象 提交于 2019-12-24 13:17:14

问题


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.

来源:https://stackoverflow.com/questions/30524322/matlab-add-additional-y-axis-linearly-scaled-to-original-and-print-to-pdf-w

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!