Assign same linewidth to a grouped barplot

조회 수: 2 (최근 30일)
Enrico Gambini
Enrico Gambini 2021년 4월 14일
댓글: dpb 2021년 4월 15일
Hello everyone,
I'm trying to assign the same linewidth to a grouped barplot, it says that i have to use the comma separated list assigment, but frankly i've never dealt with lists in matlab, and i really don't know how to do it.
v1=rand(10,1);
v2=rand(10,1);
x=[1:10];
combined=[v1,v2];
barplot=bar(x,combined,'grouped');
barplot.LineWidth=%And now i'd like to put for the 2 series the same linewidth=1
Thank you :)

채택된 답변

Mathieu NOE
Mathieu NOE 2021년 4월 14일
hello
v1=rand(10,1);
v2=rand(10,1);
x=[1:10];
combined=[v1,v2];
barplot=bar(x,combined,'grouped');
barplot(1).BarWidth = 1; % both bars are grouped so doing the mod on the first one will be applied on second bar too;
  댓글 수: 3
Enrico Gambini
Enrico Gambini 2021년 4월 14일
You interpreted it well, my sentence was wrong: i wanted to change the barwidth and not the linewidth.
Your answers are very helpful and i got it!
Thank you
dpb
dpb 2021년 4월 15일
The same syntax applies as shown before; just use the correct property name:
set(barplot,{'barwidth'},{1})
which will also work in cases where must set each handle of the handle array.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

dpb
dpb 2021년 4월 14일
편집: dpb 2021년 4월 14일
You can't use the "dot" notation with an array of handles, anyway; must use set here, or a looping construct of some sort.
set(barplot,{'linewidth'},{2})
NB: Must pass cell arrays even for single values to assign for multiple handles There are detailed examples of the use for more complicated cases in the documentation for set()

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by