Home > Net >  Histogram function plots different colours from those requested
Histogram function plots different colours from those requested

Time:03-31

I"m trying to color-code each of 4 histograms using a predefined color scheme. Here's a minimal working example:

colours = [0 32 96;
    192 0 0;
    71 207 255;
    255 143 143;
    ] / 255;

for i=1:4
    x = randn(1,100);
    subplot(1,4, i)
    values = histogram(x,   'FaceColor', colours (i, :));
end

However, in the image I'm getting, the colors are actually (slightly) different, for instance for the first histogram I get (102,121,160) instead of (0,32,96): enter image description here

CodePudding user response:

The default histogram FaceAlpha is 0.6 (ref.). Setting it to 1 should do the trick.

histogram(x,'FaceColor',[0 1 0],'FaceAlpha',1);

Very cumbersome and unexpected.

  • Related