How to scale the length of the x-axis/graph?
66 views (last 30 days)
Show older comments
Hey,
I am plotting several 2D-profiles one after another with the same Matlab-script by just changing the input files. The x-axis displays the profile meter, e.g. goes from 0m to 100m and the y-axis the depth. I want to scale the x-axis in such way that 10m in both plots are the same (e.g. if you want so 1cm).
Is that possible? So I want to use the xlim for scaling, but how?
More info:
- I save the pictures as .eps if that makes a difference...
- Matlab 2015b
Edit: I added a picture
0 Comments
Accepted Answer
the cyclist
on 16 Dec 2015
Edited: the cyclist
on 16 Dec 2015
That property is governed by the Position property of the axis.
Here is an example:
figure
subplot(2,1,1), plot(100*rand(20,1),rand(20,1))
xlim([0 100])
set(gca,'Position',[0.1300 0.5838 0.7750 0.3412])
subplot(2,1,2), plot(50*rand(20,1),rand(20,1))
xlim([0 50])
set(gca,'Position',[0.1300 0.1100 0.7750/2 0.3412])
I don't manipulate this very often, so this may not be the best way.
Before setting those position, I first did
get(gca,'Position')
for each subplot, to see what the starting positions were. They were the vectors
[0.1300 0.5838 0.7750 0.3412]
for the top subplot, and
[0.1300 0.1100 0.7750 0.3412]
for the bottom subplot. These vectors are
[xstart ystart xwidth yheight]
Then, notice that I changed the xwidth of the bottom subplot, to half of the default. In your case, you'd want to manipulate that according to whatever you choose.
Here is the resulting figure:
More Answers (3)
John BG
on 15 Dec 2015
or:
ax=gca
ax.XLim
or:
axis([xmin xmax ymin ymax])
or:
xlim([0 100])
to prevent limits changing:
xlim manual
or:
axis manual
whatever changes, to reset:
axis normal
Steven Lord
on 15 Dec 2015
If I understand what you're trying to do, you want the two axes to have the same limits (if they're the same size, you will need to do this to keep the lengths in sync.) If so take a look at LINKAXES.
See Also
Categories
Find more on Annotations 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!