Is it possible to create a bar graph with different x-Axis scale/labeling?

조회 수: 6 (최근 30일)
Hi,
I am trying to create a bar graph that looks like this:
On the x-Axis I would like to have the bars for WP on the very left with one bar distance to the bars from -12 to 20°C and then again the bars for SHVK on the very right with one bar distance.
Furthermore I am working with a table and I was wondering if it would work if i write WP and SHVK in the collumn for the temperature or if i'd have to use a different way of working with the table. Because at the moment I have 0 as the temperature but that gives out a wrong graph as there are three values for 0 on the x-Axis.
I have attached the table I am working with. I want to plot out.combinednew.([3,9,12]).
Thanks!

채택된 답변

dpb
dpb 2023년 8월 10일
편집: dpb 2023년 8월 10일
Set the first/last x values to min(x)-2/max(x)+2, respectively, then set the ticklabels for those two manually.
y = [2 2 3; 2 5 6; 2 8 9; 2 11 12]; % from bar() example for grouped
x=[0:length(y)-1]-2; % simulate similar x
y=[y(1,:);y;y(end,:)]; y(1,end)=0; y(end,1)=0; % augment y similar to desired
x=[x(1)-2 x x(end)+2]; % fixup the x vector with gap
subplot(2,1,1)
bar(x,y); % default look to match
subplot(2,1,2) % now fixup the ticklabels as desired
bar(x,y); % base plot
LABELS={'WP','SHVK'}; % the specific group labels wanted
hAx=gca; % get the axis handle
hAx.XTickLabels([1,end])=LABELS; % write those two in place of default

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by