Hold on changes appearance of histogram2

3 ビュー (過去 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 Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by