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

1 Ansicht (letzte 30 Tage)
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!

Akzeptierte Antwort

dpb
dpb am 10 Aug. 2023
Bearbeitet: dpb am 10 Aug. 2023
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

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by