help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Aw: secondary x axis


From: Ismael Diego Nunez-Riboni
Subject: Aw: secondary x axis
Date: Mon, 8 Apr 2013 11:20:43 +0200 (CEST)

> Trying to plot a figure with additional x axis on the top of the figure.
 
I had a similar issue with a second Y-axis and was always unhappy with the function that should do it out of the box (plotyy? don't remember anymore). I finally decided to do it myself with brute force, probably not the best thing, but it worked and I obtained exactly what I wanted: simply plot the ticks of your second axis (as well as the second function, with the same color) yourself. Here is an example of my code (yticks are the desired Y tick values of the second plot):
 
         gm = axis; % Get the plot axis values, once you have plotted the first plot
         
         x0 = yticks(1);
         x1 = yticks(end);
         y0 = gm(3);
         y1 = gm(4);
         
% Obtaining the parameters of a linear transformation of Y ticksof the second plot to be shown in the axis of the first plot:
         a = (y0-y1)./(x0 - x1);
         b = y1 - a.*x1;
         
            nt = yticks.*a + b;
 
            for ti = 1:length(nt)
               plot([gm(2), gm(2)-tw],[nt(ti) nt(ti)],'k-')   % Plotting the ticks, tw is a parameter for the tick width
               text(gm(2) + ts,nt(ti), num2str(yticks{oo+1}(ti)),'fontsize',10,'rotation',45,'color',grey2,'fontweight','bold') % tick labels, ts is a parameter for the distance to the ticks
            end
         
            text(gm(2) + ts + 0.2,gm(3) + (gm(4) - gm(3))./2, AXESTITLE,'rotation',90,'horizontalalignment','center','verticalalignment','middle','color',grey2,'fontweight','bold')
 
      % And here I transform the second plot function similarly as the ticks, i.e., with the same linear transform so that I can plot it in the axis of the first plot:
         X2 = xprop;
         Y2 = yprop.*a + b;
         
         plot(X2,Y2,'-r','linewidth',3,'color',grey2) % And plot it with the same color as the ticks...
 
Cheers, Ismael.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]