While using "hold on" to create a graph with multiple graphs together, the logarithmic scale on x axis is not applied.

5 ビュー (過去 30 日間)
João Sá Pereira 2023 年 11 月 27 日
コメント済み: Voss 2023 年 11 月 27 日
I want to create a multiple graph using a logarithmic scale on the x-axis, to be able to see the differences between the different values on y-axis. Altough the scale on x-axis is linear and not logarithmic. Is there another way to do what I intend, using a different function?
Here's the code i used:
pi_1=[1 1 0.643 0.472 0.371 0.297]';
pi_08=[1 1 0.632 0.467 0.367 0.295]';
pi_05=[1 1 0.614 0.459 0.362 0.291]';
pi_01=[1 1 0.588 0.448 0.354 0.285]';
s=[3.394 2.400 1.697 1.200 0.849 0.600]';
figure(1)
hold on
cum1=semilogx(s, pi_1);
cum08=semilogx(s,pi_08);
cum05=semilogx(s, pi_05);
cum01=semilogx(s, pi_01);
hold off
xlabel('Calibre, mm');
ylabel('Pi');
grid on
title('Cumulante Produto Final')
legend('Pa=1.000','Pa=0.800','Pa=0.500','Pa=0.100');
cum1.LineStyle = '-';
cum1.Color = 'blue';
cum1.Marker = 'o';
cum08.LineStyle = '-';
cum08.Color = 'red';
cum08.Marker = 'o';
cum05.LineStyle = '-';
cum05.Color = 'green';
cum05.Marker = 'o';
cum01.LineStyle = '-';
cum01.Color = 'magenta';
cum01.Marker = 'o';

サインインしてコメントする。

採用された回答

Voss 2023 年 11 月 27 日
One way to fix this is to set the 'XScale' of the axes to 'log' explicitly.
pi_1=[1 1 0.643 0.472 0.371 0.297]';
pi_08=[1 1 0.632 0.467 0.367 0.295]';
pi_05=[1 1 0.614 0.459 0.362 0.291]';
pi_01=[1 1 0.588 0.448 0.354 0.285]';
s=[3.394 2.400 1.697 1.200 0.849 0.600]';
figure(1)
set(gca(),'XScale','log') % this can go anywhere from this line down
hold on
cum1=semilogx(s, pi_1); % these can be plot() or semilogx() now
cum08=semilogx(s,pi_08);
cum05=semilogx(s, pi_05);
cum01=semilogx(s, pi_01);
hold off
xlabel('Calibre, mm');
ylabel('Pi');
grid on
title('Cumulante Produto Final')
legend('Pa=1.000','Pa=0.800','Pa=0.500','Pa=0.100');
cum1.LineStyle = '-';
cum1.Color = 'blue';
cum1.Marker = 'o';
cum08.LineStyle = '-';
cum08.Color = 'red';
cum08.Marker = 'o';
cum05.LineStyle = '-';
cum05.Color = 'green';
cum05.Marker = 'o';
cum01.LineStyle = '-';
cum01.Color = 'magenta';
cum01.Marker = 'o';
2 件のコメントなしを表示なしを非表示
João Sá Pereira 2023 年 11 月 27 日
Tanhk you, it worked perfectly!!
Voss 2023 年 11 月 27 日
You're welcome!

サインインしてコメントする。

その他の回答 (1 件)

Voss 2023 年 11 月 27 日
One way to fix this is to put the hold on afer the first semilogx() call.
pi_1=[1 1 0.643 0.472 0.371 0.297]';
pi_08=[1 1 0.632 0.467 0.367 0.295]';
pi_05=[1 1 0.614 0.459 0.362 0.291]';
pi_01=[1 1 0.588 0.448 0.354 0.285]';
s=[3.394 2.400 1.697 1.200 0.849 0.600]';
figure(1)
cum1=semilogx(s, pi_1);
hold on
cum08=semilogx(s,pi_08);
cum05=semilogx(s, pi_05);
cum01=semilogx(s, pi_01);
hold off
xlabel('Calibre, mm');
ylabel('Pi');
grid on
title('Cumulante Produto Final')
legend('Pa=1.000','Pa=0.800','Pa=0.500','Pa=0.100');
cum1.LineStyle = '-';
cum1.Color = 'blue';
cum1.Marker = 'o';
cum08.LineStyle = '-';
cum08.Color = 'red';
cum08.Marker = 'o';
cum05.LineStyle = '-';
cum05.Color = 'green';
cum05.Marker = 'o';
cum01.LineStyle = '-';
cum01.Color = 'magenta';
cum01.Marker = 'o';

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by