HBar2(mat,varargin)​%,lTitle,rTitle,lfc​olor,rfcolor,lbcolo​r,rbcolor,labels,In​terval,withText,pre​cT)

2-sided bar plot

35 Downloads

Updated 30 Nov 2017

View License

version 1.0.1
Developer: Amir H. Ansari
Feel free to use, distribute, and customize it as you like without acknowledging me. Enjoy :)
Let me know if there is any bug to fix or if you have any suggestion.
This function is for plotting two sided (left-right) bar plot.
Inputs: - mat: a 2D matrix with two columns and L rows. Column 1 and 2
are corresponding to the left and right bars respectively.
Optional Inputs:
- 'titles', {'titleLeft', 'titleRight'}: the tile of the left and right
bars. The default value is {'',''}
- 'titleVerticalOffset', titleVerticalOffset: is a number defining the
vertical offset of the titles. The default value is -0.5.
- 'faceColors', {'colorLeft', 'colorRight'}: the faceColors of the left
and right bars. The colors can be an RGB vector, or matlab character-based colors (e.g. 'r','k',...). The default value is {darkNavy,lightNavy}

- 'edgeColors', {'colorLeft', 'colorRight'}: the border colors of the left
and right bars. The colors can be an RGB vector, or matlab character-based colors (e.g. 'r','k',...). The default value is {'r','b'}

- 'titleColors', {'colorLeft', 'colorRight'}: the color of the titles
and right bars. The colors can be an RGB vector, or matlab character-based colors (e.g. 'r','k',...). The default value is {'k','k'}

- 'labels', {...}: the YTickLabels which should be written between the
left and right bars. It should be a cell of string or numeric vector. The
length should equal L. to have no labels, use {}.The default value is the numbers 1 to L (1:L).

- 'interval', interval: A number smaller than 1 showing the normalized
interval between the left and right bars. set zero for no interval, The
default value is 0.1.

- 'valueType', 'valueType': Is a string defining the presence of values. Should be one of {'both', 'right', 'left','none'}.
the default value is 'both'.

- 'precision', 'precision': Is a string defining the precision of values
used in sprintf. so it can be '%d', '%e', '%f', '%a.bf, ... The default value
is '%g'

- 'pageMargin', pageMargin: Is a number smaller than one defining the
normalized margin in the left and right sides of the figure between the
biggest bars and the border of the figure. The default value is 0.1.

- 'valueMargin', valueMargin: Is a number with the scale of the data
(mat) showing the margin between the end of bars and written values. The
default value is 0.

- 'FontName', 'FontName': The family font name of all texts in the
figure. The default is 'Helvetica'.

- 'titleFontSize', titleFontSiz: Is a number defining he font size of the left and right
titles. The default value is 11.

- 'valueFontSize', valueFontSize: Is a number defining he font size of the written values.
The default value is 10.

- 'labelFontSize', labelFontSize: Is a number defining he font size of the labels.
The default value is 10.

% - 'unit', unit: Is a string which will be added to the end of all values.
% The default value is ''.

% Example:
% HBar2(randi(100,4,2),'titles',{'2015','2016'},'titlecolors',{'k','k'},'interval',0.25,'labels',{'Summer','Fall','Winter','Spring'},...
'valueMargin',5,'unit',' h','pageMargin',0.2);
% HBar2(rand(10,2),'titles',{'aa','bb'},'titlecolors',{'k','k'},'interval',0.1,'precision','%2.2f','labels',{});
% HBar2(rand(10,2),'titles',{'aa','bb'},'faceColors',{'r','g'},'edgeColors',{'r','g'},'titlecolors',...
{'r','g'},'interval',0.1,'valueType','left','precision','%2.2f','valueMargin',0.05,'pageMargin',0.1,'FontName','Times New Roman','titleFontSize',20)

Cite As

Amir H. Ansari (2023). HBar2(mat,varargin)%,lTitle,rTitle,lfcolor,rfcolor,lbcolor,rbcolor,labels,Interval,withText,precT) (https://www.mathworks.com/matlabcentral/fileexchange/65267-hbar2-mat-varargin-ltitle-rtitle-lfcolor-rfcolor-lbcolor-rbcolor-labels-interval-withtext-prect), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2016a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Bar Plots in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.1.0

- unit option is also included
- unit option is also included

1.0.0.0

-

-