Hold on changes appearance of histogram2

3 visualizaciones (últimos 30 días)
Jonah Pearl
Jonah Pearl el 20 de Feb. de 2019
Comentada: Adam el 20 de Feb. de 2019
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 comentario
Adam
Adam el 20 de Feb. de 2019
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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by