필터 지우기
필터 지우기

Hold on changes appearance of histogram2

조회 수: 1 (최근 30일)
Jonah Pearl
Jonah Pearl 2019년 2월 20일
댓글: Adam 2019년 2월 20일
In the following code block, executing "hold on" before the histogram is created changes the appearance of the histogram in the plot. Specifically, it prevents MATLAB from drawing light grey lines demarcating the empty bins. I cannot figure out how to get the light grey lines to appear using a property. (The view is also different, but that matters less since it can be changed with the view command()). I cannot see any differences in properties between h and h2. I'd like to understand this difference. A work-around is to call hold on after the histogram has been created, but this seems like a poor solution. Thank you!
Version: Matlab 2018b. OS: Mac OS High Sierra
figure
x = rand(200,1)+rand(200,1)*3; % create data
y = rand(200,1)+rand(200,1)*3;
x = x(~(round(x)==2 | round(x)==3)); % create emtpy bins in data
y = y(~(round(x)==2)| round(x)==3);
[vals,xe,ye] = histcounts2(x, y); % set up to plot using histogram2
h = histogram2('XBinEdges',xe,'YBinEdges',ye,'BinCounts',vals, 'FaceColor', 'flat');
figure
hold on % only difference from above code
x = rand(200,1)+rand(200,1)*3;
y = rand(200,1)+rand(200,1)*3;
x = x(~(round(x)==2 | round(x)==3));
y = y(~(round(x)==2)| round(x)==3);
[vals,xe,ye] = histcounts2(x, y);
h2 = histogram2('XBinEdges',xe,'YBinEdges',ye,'BinCounts',vals, 'FaceColor', 'flat');
h
h2
  댓글 수: 1
Adam
Adam 2019년 2월 20일
Calling hold on before you have plotted anything does tend to often have unwanted effects. Certain plotting functions reset some axes properties. I can't remember off-hand, exact situations in which this happens, but calling hold on when you already have something on the axes is the usual way to do it.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by