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

Thread Subject:
problem with plotting axes and saving image

Subject: problem with plotting axes and saving image

From: Jonathan

Date: 1 Sep, 2010 17:49:06

Message: 1 of 1

Hello,

I have the following script (a sub-section of the full script). The problem I have is that when the plot is created and saved, there appears to be a second y-axis line on the left side of the plot, that is the product of 'set(ax2,'xlim',xlimit,'ytick',get(ax1,'ytick'), 'yticklabel','')' (see full code below). I cannot figure out how to eliminate this second line. Any thoughts would be much appreciated.

The overall purpose of this script is to create a second x-axis (or y-axis) that has its units as feet.
 
%% Data
cont7 = [0 -10.015 -8.59 -8.512 -7.542 -7.4 -5.075 -4.897];
cont7 = cont7.';
time = [729681 731474 733205 733340 733565 733694 733921 734374];
time = time.';

%% Plots data
h = figure;
subplot(2,3,1);
plot(cont7,time,'--.b','LineWidth',1.5,... %plot data
    'MarkerEdgeColor','k',...
    'MarkerFaceColor','w',...
    'MarkerSize',8)
set(gca,'FontSize',8)
grid on;
set(gca,'XMinorTick','on')
xmin = -30;
xmax = 0;
ymin = 729391;
ymax = 734504;
axis([xmin,xmax,ymin,ymax]);
set(gca,'YTick',[729391 729756 730121,...
    730486 730852 731217 731582 731947 732313 732678 733043 733408 733774 734140])
set(gca,'YTickLabel',{'1997' '1998' '1999',...
    '2000' '2001' '2002' '2003' '2004' '2005' '2006' '2007' '2008' '2009' '2010'})
line([0 0], [ymin ymax],'LineStyle','--','Color','y','LineWidth',1)
legend('7.0m elev.','Location','SouthEast')
xlabel('Contour Change (m)','FontSize',8)
ylabel('Time','FontSize',8)

%% Creates a second x-axis (in feet units) at top of plot
ax1 = gca;
set(ax1,'box','off');
ax2 = axes('Position',get(ax1,'Position'),...
    'XAxisLocation','top',...
    'color','none');
m2ft = 3.281;
xlimit = [xmin*m2ft,xmax*m2ft]; % ylimits in feet
set(gca,'FontSize',8)
set(ax2,'xlim',xlimit,'ytick',get(ax1,'ytick'), 'yticklabel','')
xlabel('Contour Change (ft)');

%% Save plot
fname=sprintf('alsea%d_EDA',i);
print('-dpng','-r300',[fname '.png']);


Thanks
Jon

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us