Axis numbers on histogram

3 次查看(过去 30 天)
Hello there,
I'm trying to plot a histogram plot of departure times on the 24-hour time scale.
Here is an example of what I'm trying to achieve: http://img593.imageshack.us/img593/3032/depaturetime.jpg
My question is: How can I get the x-axis to start at 5am and finish at 4am like it is in the example. When I plot it it goes from 0 - 24.
Also how could I plot the cumulative distribution over the histogram.
My code:
DepartureTimes = load('Departure Times.txt')
h = hist(DepartureTimes,24);
h = h/sum(h);
bar(h, 'DisplayName', 'Depature Times');
legend('show');
Many thanks for your help
John

采纳的回答

Image Analyst
Image Analyst 2012-1-7
% Demo to plot histogram and cdf of grayscale image.
% By ImageAnalyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 14;
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Let's compute and display the histogram.
[pixelCount grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(pixelCount);
title('Histogram of image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
grid on;
% Compute the CDF
cdf = cumsum(pixelCount) / numel(grayImage);
% Plot both hist and cdf on same plot
subplot(2,2,3);
bar(pixelCount);
hold on;
z = zeros(1,length(pixelCount));
plotyy(grayLevels, z, grayLevels, cdf);
title('Histogram and CDF of image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
grid on;

更多回答(1 个)

Image Analyst
Image Analyst 2012-1-7
Did you try xlim()?
  2 个评论
John
John 2012-1-7
Hello,
Thank you, xlim() worked. Would you know how I could plot the cumulative distribution over the histogram with the scale on the right hand side of the chart as in the example? I'm having no luck :(
http://img593.imageshack.us/img593/3032/depaturetime.jpg
Appreciate any help
John
Image Analyst
Image Analyst 2012-1-7
See full demo code below.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Blue 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by