Assign same linewidth to a grouped barplot

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 :)

 Respuesta aceptada

Mathieu NOE
Mathieu NOE el 14 de Abr. de 2021
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 comentarios

maybe I interpreted that the question could be related to the bar width and not the surrounding line width
in the latter case you can do this :
v1=rand(10,1);
v2=rand(10,1);
x=[1:10];
combined=[v1,v2];
barplot=bar(x,combined,'grouped');
barplot(1).LineWidth = 3;
barplot(2).LineWidth = 2;
Enrico Gambini
Enrico Gambini el 14 de Abr. de 2021
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
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.

Iniciar sesión para comentar.

Más respuestas (1)

dpb
dpb el 14 de Abr. de 2021
Editada: dpb el 14 de Abr. de 2021
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()

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Productos

Versión

R2021a

Preguntada:

el 14 de Abr. de 2021

Comentada:

dpb
el 15 de Abr. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by