help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting plots in Octave to show colors like Matlab.


From: Hartmut
Subject: Re: Getting plots in Octave to show colors like Matlab.
Date: Sun, 23 Apr 2017 11:33:35 -0700 (PDT)

The CData property doesn't seem to be implemented in the Octave version of
the bar command.

You could work around this by plotting all the single bars individually. And
setting an individualy color of each individual bar. The following code runs
for several seconds, but works generally fine for me (in Octave 4.2.1):

--- code ----
pkg load image
rgbImage = imread('marbles.jpg');  % Load image Image of marbles.jpg:
http://i.imgur.com/17S9PUK.jpg
hsvImage = rgb2hsv(rgbImage);         % Convert the image to HSV space
hPlane = 360.*hsvImage(:, :, 1);      % Get the hue plane scaled from 0 to
360
binEdges = 0:360;                 %# Edges of histogram bins
N = histc(hPlane(:),binEdges);    %# Bin the pixel hues from above

C = colormap(hsv(360));  %# create an HSV color map with 360 points
stepsize = 10; % stepsize 1 runs for a while...

for n=binEdges(2:stepsize:end)   %# Plot the histogram, one bar each
    if (n==1), hold on, end
    h=bar(n,N(n));
    set(h,'FaceColor',C(n,:));   %# set the bar color individually
end

axis([0 360 0 max(N)]);           %# Change the axes limits
set(gca,'Color','k');             %# Change the axes background color
set(gcf,'Pos',[50 400 560 200]);  %# Change the figure size
xlabel('HSV hue (in degrees)');   %# Add an x label
ylabel('Bin counts');             %# Add a y label
--- code ---

By the way, Matlab seems to also have the same problems, when using a Matlab
version of 2014b or newer, see [1]

I hope this helps.

    Hartmut


[1]
https://de.mathworks.com/matlabcentral/answers/99092-how-do-i-define-colors-for-individual-bars-on-my-bar-graph-according-to-their-values-in-matlab





--
View this message in context: 
http://octave.1599824.n4.nabble.com/Getting-plots-in-Octave-to-show-colors-like-Matlab-tp4682982p4682988.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]