histogram2 vs pcolor: on making the coloring of the former one smooth

When making a 2d graph using pcolor() or a surface plot with surf(), MATLAB evaluates the function on a grid and gives each piece of this grid a corresponding color. Adding
shading interp
makes the transitions between colors smooth, so that the grid is no longer visible.
It seems though, that this option does not work for a histogram2(), even though superficially such an object looks very similar.
Is there a way to make the output graphics object histogram2() smooth, with or without converting it into an ordinary figure?

5 Comments

The output of histogram2 is an "ordinary" figure. Are there sub-ordinary figures?
A histogram is wanted to have visible edges to distinguish the bars. What do you want to achieve exactly? Can you post a screenshot and explain the required differences? What exactly should look "smooth"?
@Jan Simon Thanks for your comment. There is some complicated function of two coördinates I am plotting in different ways. The first picture is the exact way: vectorizing, meshgrid, pcolor (technically, it is the top view of surf here, but that's not really the point) and shading interp for smoothening out the mesh.
Secondly, I calculate the same function using some Monte Carlo scheme. In order to make a graph again for comparison (Ideally, it looks as close as possible to the original one), I use histogram2, but I don't like that histogram2 makes the picture so pixelized, So it would seem to make sense if shading interp again would make the coloring smoother.
I know, looked at it from the side, the bars will still remain bars. This may be little bit of a pity, but I am most interested in the top view.
Note that axes or the coloring interval are not made consistent yet between the two plots, but I don't expect too much trouble there.
If the lower data have been calculated inside the boxes, drawing a smooth image would be nice, but misleading. Such an anti-aliasing would pretend a solution obtained in a much higher resolution and in consquence it is not scientifically correct.
You could use the output of histogram2 and create the diagram by you own with pcolor instead of teh bars.
Thanks again for your answer. I'm most interested in how the 'global shape' of the function compares in a glimp, so the resolution as such is as good as it needs to be for my purpose. The fact that one looks smooth and the other one pixelized makes it harder to compare.
Do you mean there is a class property of histogram2 containing the Z-values?
For now, playing with options as 'EdgeAlpha' and 'ShowEmptyBins' has already given me a more useful picture than the original one.
>> Do you mean there is a class property of histogram2 containing the Z-values?
Yes! The return value of histogram2 contains the values of the bins:
>> h = histogram2(1:5, 2:6);
>> h.Values
ans =
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
You can use these values with your favorite plotting tools to get exactly what you need.

Sign in to comment.

Answers (0)

Categories

Products

Asked:

on 4 Jul 2017

Commented:

on 18 Feb 2020

Community Treasure Hunt

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

Start Hunting!