How to scale the length of the x-axis/graph?

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

 Akzeptierte Antwort

the cyclist
the cyclist am 16 Dez. 2015
Bearbeitet: the cyclist am 16 Dez. 2015

4 Stimmen

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:

1 Kommentar

Sina
Sina am 17 Dez. 2015
Bearbeitet: Sina am 17 Dez. 2015
Thanks. It looks very nice but in my case it doesn't really work... It might be because I don't have subplots or/and I am using another self-made Matlab script as a function for plotting. I don't know. For me it also changed the y-axis and the font sizes. But if I want to plot the same figure twice in two subplots it won't even plot it twice so maybe there is something else wrong... If it helps for anyone else: I am using patch for plotting... Thanks again anyways!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (3)

the cyclist
the cyclist am 15 Dez. 2015

0 Stimmen

set(gca,'XLim',[0 100])

1 Kommentar

Sina
Sina am 15 Dez. 2015
Thanks for the fast reply but that is not what I am looking for. Maybe I was not clear enough. I have XLim = [0 100] for the 100m Profile and XLim = [0 50] for the 50m Profile. What comes out are two plots that have the same width, e.g. if you would print the two figure without rescaling the length of the two x-axes are the same, e.g. 10cm. But what I want is that it is scaled. So If I print the two figures the x-axis of the 100m profile is 10cm and the x-axis of the 50m profile is 5cm...

Melden Sie sich an, um zu kommentieren.

John BG
John BG am 15 Dez. 2015

0 Stimmen

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

1 Kommentar

Sina
Sina am 15 Dez. 2015
If you didn't already: Please also read my comment to the above answer.
I don't think that I want to change the XLim. I basically want to shrink the graph/figure/axis, so that the ratio of the profiles stay the same. E.g. 10m is the same in both plots...
I'll try to add an image.

Melden Sie sich an, um zu kommentieren.

Steven Lord
Steven Lord am 15 Dez. 2015

0 Stimmen

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.

1 Kommentar

Sina
Sina am 15 Dez. 2015
I am not sure if we are on the same page. I added a picture for clarification. I don't think I want to have the two axes to have the same limits and definitely I don't want them to have same size...
I think the picture makes it clear hope
The Linkaxes is probably not working for me as I don't produce the figures in the same Matlab-script...

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 15 Dez. 2015

Bearbeitet:

am 17 Dez. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by