Plotting hist3 atop one another with separate colormaps
1 次查看(过去 30 天)
显示 更早的评论
I am attempting to plot two hist3 plots on top of one another with separate colormaps. Each one works fine individually, and the colormaps are custom ones I made with the zero values transparent. The first acts as a kind of shadow (see first picture), whereas the second contains data which lies on the same spatial axis.

Each is being applied the colormap of the second hist3, despite them being plotted on top of eachother with a transparent 0 (see second picture).

Lots of sources have suggested adding handles to each hist3 plot and assigning colormaps using something like
colormap(h1, shadow_map)
but every time I do that nothing appears at all. I have also tried just physically overlaying the plots on top of eachother by manually creating different axes and setting them on top of eachother but then only the second plot appears at all. I cant help but think I am going to the hardware store for a head of lettuce here, is there a different type of plot I should be using?
rcdv = figure;
hist3(shadow.rcdv, [100, 100], 'CdataMode', "auto", 'EdgeColor', 'none');
colormap(shadow_map);
axis xy;
ylim([0, fixed.dvmax]);
xlim([0, fixed.rcmax]);
yticks([0, shadow.dv_bounds, fixed.dvmax]);
xticks([0, shadow.rc_bounds, fixed.rcmax]);
pbaspect([1 (fixed.dvmax/fixed.rcmax) 1]);
view(2);
set(gca, 'YDir', 'reverse');
grid off;
hold on
hist3([data.combined.raw(:,1) data.combined.raw(:,2)], [20, 20], 'CdataMode', "auto", 'EdgeColor', 'none');
colormap(spectrum1);
axis xy;
ylim([0, fixed.dvmax]);
xlim([0, fixed.rcmax]);
yticks([0, shadow.dv_bounds, fixed.dvmax]);
xticks([0, shadow.rc_bounds, fixed.rcmax]);
pbaspect([1 (fixed.dvmax/fixed.rcmax) 1]);
view(2);
set(gca, 'YDir', 'reverse');
grid off;
1 个评论
Walter Roberson
2024-12-10
When you created multiple axes and set them on top of each other, did you remember to set the background color for the overlay axes to be 'none' ?
回答(1 个)
colordepth
2024-12-16
A practical method for overlaying two plots with different colormaps is detailed here: https://www.mathworks.com/matlabcentral/answers/2143959-multiple-colormaps-with-or-without-transparency. This solution successfully overlays two plots by using separate axes, each with its own colormap. The key to making both plots visible is setting transparency with the “alpha” function (https://www.mathworks.com/help/matlab/ref/alpha.html), which prevents one plot from completely obscuring the other. This way, you can ensure both histograms are visible and maintain their distinct color schemes.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Color and Styling 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!