필터 지우기
필터 지우기

bar chart 2 data sets side by side with different axis

조회 수: 1 (최근 30일)
cdlapoin
cdlapoin 2022년 1월 29일
댓글: cdlapoin 2022년 1월 29일
hold on;
yyaxis left
bar(T3_blocked)
yyaxis right
bar(S1_free)
set(gca, 'XTickLabel',name)
set(gca, 'XTick',1:length(name))
set(gca, 'XTickLabelRotation',45)
hold off;
produces:
how can I have the two bars for each material side by side, so the y-axes are both increasing in the same direction (up)?

채택된 답변

Voss
Voss 2022년 1월 29일
편집: Voss 2022년 1월 29일
You can do that by using abs(S1_free) and specifying the locations and widths of the bars:
T3_blocked = [2 1.95 1.5 0.1 1.4]*1e-7;
S1_free = -[1.4 1.4 1 2.9 2]*1e-4;
name = strcat('PZT-',num2cell('A':'E'));
n = numel(name);
hold on;
yyaxis left
bar((1:n)-0.2,T3_blocked,0.4); % locations, heights, width
yyaxis right
bar((1:n)+0.2,abs(S1_free),0.4); % locations, heights, width
set(gca, 'XTickLabel',name)
set(gca, 'XTick',1:length(name))
set(gca, 'XTickLabelRotation',45)
hold off;

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 1월 29일
How about taking the absolute value of S1_free?
bar(abs(S1_free));
  댓글 수: 1
cdlapoin
cdlapoin 2022년 1월 29일
This paritially works except the bars are overlapping

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

카테고리

Help CenterFile Exchange에서 Bar Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by