本文介绍如何使用matlab定制自己的直方图。
bar()
函数创建柱状图bar()
画的bin的高度跟数据相关bar()
数据每一列一个group,有几列数据就画出几组柱状图close all;
clc
clear;
% bins data
num_bins = 5;
num_methods = 3;
data = rand(num_bins, num_methods);
% draw the graph
figure;
handle_bar = bar(data);
ax = gca;
% tight the graph
axis tight;
% title and labels
title('\bf\color[rgb]{0,0,0}histgram');
xlabel('$\mathbf{\Gamma(x)}$ \textbf{value}', 'Interpreter', 'latex');
%xlabel('\bf\color[rgb]{0,0,0}\Gamma(x)', 'Interpreter', 'tex');
ylabel('\bf\color[rgb]{0,0,0}percentage');
% ytick : add % and use Bold Font with the TeX Interpreter
ytick = ax.YTick;
ytick_label = cell(length(ytick), 1);
for i = 1:length(ytick)
ytick_label(i) = {['\bf', num2str(ytick(i)*100), '%']};
end
ax.YTickLabel = ytick_label;
% Grid
ax.YGrid = 'on';
% legend
leg_handle = legend('\bf{}method 1', '\bf{}method 2', '\bf{}method 2', 'Location', 'northeast');
% figure position and size : [left bottom width height]
set(gcf, 'Position', [100, 500, 400, 260]);