Hı,
How can I draw the graph whose image I added? can you help me please?
The relationship between values is briefly,
drift ratio - displacement
displacement - base shear
I use the hold on command, but displacement and drift ratio are on the same axis (x axis).
How can I define separate axis like here?

댓글 수: 9

Sam Chak
Sam Chak 2024년 4월 7일
이동: Sam Chak 2024년 4월 7일
Refer to the examples in yyaxis documentation.
x = linspace(0,10);
y = sin(3*x);
yyaxis left
plot(x,y)
z = sin(3*x).*exp(-0.25*x);
yyaxis right
plot(x,z)
rahan sof
rahan sof 2024년 4월 7일
이동: Sam Chak 2024년 4월 7일
Thanks for your feedback but that's not what I'm talking about.
plot(dispalacement, force)
plot(displacement, dirft )
In the same chart, the drfit ratio axis must be up:
Sam Chak
Sam Chak 2024년 4월 7일
I haven't previously attempted to create a chart with two x-axes and two y-axes. Such a graph can be quite perplexing to interpret, as it may resemble an optical illusion. Let me investigate whether it is possible to achieve this using the linkaxes() command.
rahan sof
rahan sof 2024년 4월 7일
Thank you very much.
One method is to use the XAxisLocation property of the axes. Try exploring how it works and see if works out.
x = 0:0.01:10;
y = sin(x);
plot(x, y), grid on
% Create a second x-axis object at the top
ax2 = axes('Position', get(gca, 'Position'), 'Color', 'none', 'XAxisLocation', 'top');
Hi,
You can try this workaround:
% Sample data
x1 = linspace(0, 100, 100);
y1 = sin(x1);
x2= linspace(0,10,100)
x2 = 1x100
0 0.1010 0.2020 0.3030 0.4040 0.5051 0.6061 0.7071 0.8081 0.9091 1.0101 1.1111 1.2121 1.3131 1.4141 1.5152 1.6162 1.7172 1.8182 1.9192 2.0202 2.1212 2.2222 2.3232 2.4242 2.5253 2.6263 2.7273 2.8283 2.9293
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
figure;
ax1 = axes;
plot(x1, y1)
xlabel('x')
ylabel('sin(x)')
xlim(ax1,[0 100])
% Create the second axes for the top
ax2 = axes('Position', get(ax1, 'Position'), 'XAxisLocation', 'top', 'YAxisLocation', 'right');
hold on
plot(ax2, x2,y1)
xlim(ax2,[0 10])
rahan sof
rahan sof 2024년 4월 7일
Thank you, but a relationship between x and ax2 is not defined here. Drift rates corresponding to displacement are needed in the graph. Thank you.
I'm not sure about the requirement but you can define the relation bewteen them using the equation.
x2=(relation with x)*x;
Hope this will help!
rahan sof
rahan sof 2024년 4월 7일
Unfortunately it didn't work but thank you very much.

댓글을 달려면 로그인하십시오.

답변 (1개)

Avni Agrawal
Avni Agrawal 2024년 6월 28일

0 개 추천

Hi,
I understand that trying to plot two different y-axes for the same x-axis in MATLAB, you can use the yyaxis function. This allows you to create a plot with two y-axes, one on the left and one on the right, each with its own scale.
Here ia an example of how you can plot the relationship between drift ratio and displacement on one y-axis, and displacement and base shear on the other y-axis:
% Sample data
displacement = 0:0.1:10; % Example displacement data
drift_ratio = displacement * 0.05; % Example drift ratio data
base_shear = displacement * 2; % Example base shear data
% Create figure
figure;
% Plot drift ratio vs. displacement on the left y-axis
yyaxis left;
plot(displacement, drift_ratio, '-b', 'LineWidth', 1.5);
ylabel('Drift Ratio');
xlabel('Displacement');
hold on;
% Plot base shear vs. displacement on the right y-axis
yyaxis right;
plot(displacement, base_shear, '-r', 'LineWidth', 1.5);
ylabel('Base Shear');
% Add title and legend
title('Displacement vs. Drift Ratio and Base Shear');
legend('Drift Ratio', 'Base Shear');
% Adjust figure properties
grid on;
I hope this helps!

카테고리

도움말 센터File Exchange에서 Graphics에 대해 자세히 알아보기

제품

릴리스

R2024a

질문:

2024년 4월 7일

답변:

2024년 6월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by