bar graph with broken y-axis

32 ビュー (過去 30 日間)
Tim Gordon
Tim Gordon 2011 年 11 月 15 日
コメント済み: Sebin 2023 年 8 月 16 日
Does anyone have code for creating a vertical bar graph with a broken y-axis?

回答 (5 件)

Liam
Liam 2023 年 8 月 5 日
編集済み: Liam 2023 年 8 月 5 日
For anyone else trying to figure this out in the future, this can be accomplished with a tiled plot. Example:
% split bar graph - Liam Hurlburt (she/her) 2023.08.05
% input data here
barGraphData=[210 250 2 4 3 1; 275 225 3 4 5 2];
% set colors here
color1="#0A1F3E"; % very dark blue
color2="#1F4373"; % dark blue
color3="#2B95B7"; % electric blue
color4="#D1E4EC"; % light blue
color5="#931F32"; % red #1
color6="#B1272C"; % red #3
% set relative tile height here, higher numbers make
% top chart smaller. Minimum vaule = 2 (integers only)
tileRelativeHeight=3;
figure1 = figure; % Creates figure
t=tiledlayout(tileRelativeHeight,1); % creates tiled layout
% set Y axis label here
t.YLabel.String = 'y axis label';
%% top plot
ax1 = nexttile;
b=bar(barGraphData);
b(1).FaceColor = color1; % this section coordinates
b(2).FaceColor = color2; % colors in the top and
b(3).FaceColor = color3; % bottom plots, it can be
b(4).FaceColor = color4; % commented out to use
b(5).FaceColor = color5; % default colors
b(6).FaceColor = color6;
% uncomment line below to make make top plot logartigmic
% set(gca,'YScale','log')
set(gca,'TickLength',[0 0]) % removes tick marks and
set(gca,'Xtick',[]) % x-axis labels between plots
% legend labels go here
legend('data 1', 'data 2','data 3','data 4', 'data 5', 'data 6')
% set y limits for top plot here
ylim([200 300]);
%% bottom plot
ax2 = nexttile(2,[(tileRelativeHeight-1) 1]);
b=bar(barGraphData);
b(1).FaceColor = color1; % this section coordinates
b(2).FaceColor = color2; % colors in the top and
b(3).FaceColor = color3; % bottom plots, it can be
b(4).FaceColor = color4; % commented out to use
b(5).FaceColor = color5; % default colors
b(6).FaceColor = color6;
% x axis labels go here
set(gca,'xticklabel',["Series A","Series B"]);
set(gca,'TickLength',[0 0]) % coordinates axis tick styles between plots
% set y limits for bottom plot here
ylim([0 10]);
% adjust space between plots here, suggested
% values are 'tight' and 'none'
t.TileSpacing = 'tight';
  1 件のコメント
Sebin
Sebin 2023 年 8 月 16 日
It works well and the resulting graph looks fancy!
Thank you so much!!

サインインしてコメントする。


Tim Gordon
Tim Gordon 2011 年 12 月 10 日
Yes, I want to do what I asked about.

KAE
KAE 2022 年 6 月 1 日

Walter Roberson
Walter Roberson 2011 年 11 月 15 日
  1 件のコメント
Tim Gordon
Tim Gordon 2011 年 11 月 15 日
Nope. This only seems to work for scatter plots. I want a vertical bar plot.

サインインしてコメントする。


Daniel Shub
Daniel Shub 2011 年 11 月 16 日
Are you sure you want to do this? In my opinion this rarely looks good and also is usually not the best way to convey information. What about an insert plot showing the small values? You cannot do this with standard MATLAB. You could play around with placing patches over the bars, but it is not going to look professional. I think you can do this with SigmaPlot.

カテゴリ

Help Center および File ExchangeDiscrete Data Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by