Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Jan Böttner
Jan Böttner le 10 Août 2023
Commenté : Jan Böttner le 10 Août 2023
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!

Réponse acceptée

dpb
dpb le 10 Août 2023
Modifié(e) : dpb le 10 Août 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

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by