How can we change each bar in bar chart in MATLAB [duplicate] - matlab

This question already has answers here:
How can I change the color of bars in bar graph?
(5 answers)
Closed 1 year ago.
I have a bar chart in Matlab. and I want to change every 6 bar to the same color. For example, the first 6 of them to the red, the second 6 of them to the blue, the third 6 of them to green, and the fourth 6 of them to black. Here is my code:
data_forest=xlsread('for.xlsx');
data_forest=data_forest';
x=[1:24];
name=transpose({'ET','SM','T','R','Sens','Soil T',...
'ET','SM','T','R','Sens','Soil T',...
'ET','SM','T','R','Sens','Soil T',...
'ET','SM','T','R','Sens','Soil T'});
b=bar(x,data_forest,'FaceColor','flat');
set(gca,'xTick',(1:1:24));
set(gca,'xticklabel',name);
Could anybody help me?

The most straightforward way is just draw 4 times with different colors.
data=rand(24,1);
colors={'r','g','b','k'};
figure();
hold on;
for ii=0:3
bar(ii*6+(1:6),data(ii*6+(1:6)),'FaceColor',colors{ii+1})
end

Related

Fill pattern for Bar graph or StackedBar in Jasper Report [duplicate]

This question already has answers here:
How to set stacked bar chart series color dynamically?
(1 answer)
How do I create and distribute diagonal stripes on a rectangle?
(2 answers)
Closed last month.
How to use fill parttern for the Bar or Stacked Bar graph in Jasper Report?
Can anyone give some instructions or a easy example?
Many thanks.
My expecting is somethink like the graph beblow,and I want to use diagonal stroke to fill the bar.

Is it possible to tell the human readable color (ex. pink, white) from RGB/Hex code in Swift? [duplicate]

This question already has answers here:
Check if color is blue(ish), red(ish), green(ish),
(3 answers)
Closed 1 year ago.
I'm trying to build an app for a class project that finds the most dominant color of an image. While it's not hard to extract the most dominant colors RBG code, I was wondering if there is a way to use this code to get us the name of the color like red color or blue color.
I understand this would be technically complex since there are so many different RGB values but I was wondering if that had been done before. I'm using Swift to develop this app.
This question is not swift related but more a general programming problem. There are multiple ways to solve this.
The first approach would be to create a list of colors you want to separate, or get it from somewhere. Then create a function that maps a random RGB value onto the nearest values from the list (you can do least squares or any kind of definition of 'nearest values').
Another solution would be to again use a mapping but based on the angle of the rgb values when mapped into an rgb color wheel (https://www.pikpng.com/pngl/b/113-1130205_alt-text-rgb-led-color-mixing-chart-clipart.png, http://www.procato.com/rgb+index/).
Anyway, there are multiple solutions online and also on stack overflow (RGB color space to raw color name mapping, https://github.com/ayushoriginal/Optimized-RGB-To-ColorName)

chart.js line for only part of the labels

I'm making a chart via chart.js with 6 labels; 6 bars are displayed. I also have to draw a line, but only between labels/bars 3 and 4 .. so for labels 1,2,5 and 6 no line is displayed. How is this done ?
I found the solution: just fill the data with null for the labels/bars where you don't want a line to be drawn.

Objective C - UI Slider Pointer move only from one range value to other [duplicate]

This question already has answers here:
iOS how to make slider stop at discrete points
(5 answers)
Closed 9 years ago.
I am working on UISlider functionality. I have only 4 range values (0, 1, 2, 3). So, I have given minimum value as 0 and maximum as 3. But my slider is not directly switching from 0-1, 1-2, 2-3. It is stopping in between 0-1 also. How to achieve this. I don't want to stop my slider pointer in-between my range values.
Please guide me the best approach for the above scenario.
When you handle the value changed callback from the slider, modify the value. Something like:
slider.value = roundf(slider.value);

iPhone : How to display multiple colors in progress bar?

I want to display multiple colors in progressbar.
for example,
Lets say there are three time portion in app.
Starting from 0 to 1 min it should display gray color.
from 1 to 4 min it should display blue color
and from 4 to 13 min it should display red color.
So at the end progressbar should look with three color gray,blue,red.
How can I get multiple colors?
If you target iOS5, use a custom background image for your UIProgressView (progressImage property).