I do not know why the figure is not depicted, however, you can click on Question.png to see the figure. Thanks.
How to change title and color of bars in groupe bar3?
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello everyone,
I am not very good in Matlab and will appreciate if you help me.
I have writen the following code and get the results. However, I want to do two changes:
figure(1);
hold on;
%First x value
xval = 1;
h = bar3(HV_array_for_different_number_of_honest_vehicles,'grouped');
Xdat = get(h,'Xdata');
for ii=1:length(Xdat)
Xdat{ii}=Xdat{ii}+(xval-1)*ones(size(Xdat{ii}));
set(h(ii),'XData',Xdat{ii});
end
%Second x value
xval = 2;
h = bar3(TV_array_for_different_number_of_honest_vehicles,'grouped');
Xdat = get(h,'Xdata');
for ii=1:length(Xdat)
Xdat{ii}=Xdat{ii}+(xval-1)*ones(size(Xdat{ii}));
set(h(ii),'XData',Xdat{ii});
end
xlim([0 3]);
view(3);
xlabel('x');
ylabel('y');
zlabel('z');
The left figure is the result of code and I want to have the righ figure with the follwoing changes:
1) the color of each group should be fix. For instance, grren, red, and blue.
2) The x and y axises should be labled as it is mentioned.
답변 (1개)
Jaswanth
2024년 10월 25일
Hi,
To change the color of a specific group of data when using the "bar3" function in MATLAB, you can adjust the properties of individual bars using the “FaceColor” property. By setting “FaceColor” to a specific color (using an RGB triplet), you can override the colormap for that particular bar.
Refer to the following MATLAB Answer explaining the process of changing the color of bars: https://www.mathworks.com/matlabcentral/answers/867253-setting-color-to-certain-data-in-3d-plot-keeping-rest-of-data-following-colormap#answer_1449546
Also, you can customize the tick marks on your MATLAB plot axes by using the “xtick”, “xticklabels”, “ytick”, and “yticklabels” functions. Refer to the following MathWorks example on Customizing the tick values and labels: https://www.mathworks.com/help/matlab/creating_plots/change-tick-marks-and-tick-labels-of-graph-1.html
You may refer to the following MathWorks documentation to know more about the functions mentioned above:
- xtick: https://www.mathworks.com/help/matlab/ref/xticks.html
- ytick: https://www.mathworks.com/help/matlab/ref/yticks.html
- xticklabels: https://www.mathworks.com/help/matlab/ref/xticklabels.html
- yticklabels: https://www.mathworks.com/help/matlab/ref/yticklabels.html
Hope this is helpful!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!