When using the bar3 function, the colours of the bars depend on the column or row the data is in. Example:
data = peaks(20);
bar3(data);
view(-135,30)

How can I make it that the colour of each bar only depends on the height (zdata) of that bar?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is quite difficult to mess around with the colours of the bars, as all the bars are constructed with patches. You’ll have to change the zdata of the vertices of the patches; since this is not very straightforward, I’ve made a function just for this purpose: bar3c
Example:
Edit
If you want to use other colors, simply change the colormap.
If you want to set a whole range to get one same color instead of getting a gradient between your min/max values, you’ll have to change the call to
makecdata. Now it uses thezdatato specify its color, you can easily change that to give a range a specific color.Actually, I just did that and the result can be found here.
Example: