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

4 次查看(过去 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 中查找有关 2-D and 3-D Plots 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by