Plot a figure with 2 x-axis and a single y-axis.
1 view (last 30 days)
Show older comments
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/331466/image.jpeg)
I am trying to plot a figure on matlab with 2 x-axis. The y-axis is y=x^2.
First x-axis is x and 2nd x-axis is 1/x as shown in figure.
0 Comments
Answers (1)
Abhishek Gangwar
on 15 Jul 2020
clc;
clear;
close all;
x1 = 1:40;
y1 = x1.^2;
line(x1,y1,'Color','r')
ax1 = gca; % current axes
ax1.XColor = 'r';
ax1.YColor = 'r';
ax1_pos = ax1.Position; % position of first axes
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'YAxisLocation','right', ...
'Color','none');
x2 = 1./x1;
y2 = x2.^2;
line(x2,y2,'Parent',ax2,'Color','k');
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!