Hi,
I'm having a problem plotting a vertical line on a histogram plot. The histogram appears fine but the line does not show up. I've tried both the mothod given in
and using 'plot(ACH(:,1),ACH(:,2));' but in both instances the line isn't visible.
For the histogram I'm using 'histogram(priors1010(:,1), nbins, 'FaceColor','r'); hold on;'
I'm using MATLAB R2018a.
Can anyone advise as to how to make the vertical line visible?
Thanks

댓글 수: 2

Rik
Rik 2019년 9월 11일
Try to make a MWE so we can run your code without any other dependencies and can reproduce your issue.
Thanks for replying - here's a MWE
clear; close all;
pd = makedist('normal',0,0.5');
testdata=random(pd,1000);
figure('WindowStyle','docked');
histogram(testdata);
hold on;
line([1, 1], 2, 'LineWidth', 2, 'Color', 'k');
Cheers, Rebecca

댓글을 달려면 로그인하십시오.

 채택된 답변

Bruno Luong
Bruno Luong 2019년 9월 11일
편집: Bruno Luong 2019년 9월 11일

0 개 추천

Your y-ccordinates "2" makes the line reduce to a single point. Try
line([1, 1], ylim(gca), 'LineWidth', 2, 'Color', 'k');

댓글 수: 3

Rebecca Ward
Rebecca Ward 2019년 9월 11일
Of course, in fact that was a typo and I had it correct in my original code.
But now I've run the test code and corrected the typo there, gone back to my original code and it is now working - having made no changes to it. A bit bizarre, but at least it works.
Many thanks for taking the time to point out the error.
Cheers,
Rebecca
If upgrading to release R2018b or later is an option, there is a new function named xline that will do this and will still appear even if you change the Y limits of the axes.
%% Create a sample plot
plot(1:10)
xline(5);
% Note that the line extends from the bottom of the axes to the top
%% Change the Y limits
axis([1 10 5 15])
% The line still spans the entire axes
%% Enable panning up and down
pan yon
% If you pan up and down, no matter how far you go you can see the line
Rebecca Ward
Rebecca Ward 2019년 9월 11일
Perfect, thankyou :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Histograms에 대해 자세히 알아보기

제품

릴리스

R2018a

태그

질문:

2019년 9월 11일

댓글:

2019년 9월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by