MATLAB Answers

How can I label two axys in the same plot?

16 views (last 30 days)
Gianmarco Polizia
Gianmarco Polizia on 5 Dec 2017
Answered: Sonam Gupta on 8 Dec 2017
Hello everybody. I have a plot with 2 x-axys and 2 y-axys. I want to put a label for the x-axys on the bottom of the graph and another label on the top of the graph under the title of the graph.
Finally I want to put a label for two y-axys, one label on the left of the graph and another label on the right of the graph.
I hope I have been most clear as possible. Thanks
Gianmarco

  0 Comments

Sign in to comment.

Answers (1)

Sonam Gupta
Sonam Gupta on 8 Dec 2017
You can do this as follows:
x1 = 1:10;
y1 = 1:2:20;
y2 = x1;
x2 = y1;
close all;
figure (9)
ax1 = gca;
hl1 = line(x1,y1,'Color','r');
set(ax1,'XColor','r','YColor','r')
ylabel(ax1,'y-axis-left')
xlabel(ax1,'x-axis-bottom')
ax2 = axes('Position',get(ax1,'Position'),'XAxisLocation','top',...
'YAxisLocation','right','Color','none','XColor','k','YColor','k');
hl2 = line(x2,y2,'Color','k','Parent',ax2);
ylabel(ax2,' (y-axes-right)')
xlabel(ax2,'x-axis-top')

  0 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!