Naming x-values in bar(x,y)

Julian el 23 de Oct. de 2023
Actividad más reciente Respuesta de Karol Ondrejkovic a las el 5 de Feb. de 2024

I know the latest version of MATLAB R2023b has this feature already, put it should be added to R2023a as well because of its simplicity and convenience.
Basically, I want to make a bar graph that lets me name each column in a basic bar graph:
y=[100 99 100 200 200 300 500 800 1000];
x=["0-4" "5-17" "18-29" "30-39" "40-49" "50-64" "65-74" "75-84" "85+"];
bar(x,y)
However, in R2023a, this isn't a feature. I think it should be added because it helps to present data and ideas more clearly and professionally, which is the purpose of a graph to begin with.
Adam Danz
Adam Danz el 23 de Oct. de 2023 (Editada a las el 23 de Oct. de 2023)
@Julian, just convert your string to categoricals.
y=[100 99 100 200 200 300 500 800 1000];
x=["0-4" "5-17" "18-29" "30-39" "40-49" "50-64" "65-74" "75-84" "85+"];
bar(categorical(x,x),y)
Karol Ondrejkovic
Karol Ondrejkovic el 5 de Feb. de 2024
@Adam Danz Thank you for the post. I just woder how do you flip the position of 5-17 category on the x-axis using:
bar(categorical(x,x), y)
instead of
bar(categorical(x), y)
Could you please provide a short comment on this?
Julian
Julian el 24 de Oct. de 2023
Thanks, I didn't know you could do that, that's exactly what I was trying to do.
Kilsu Kim
Kilsu Kim el 23 de Oct. de 2023
Hello,
As you said, the feature specifyng bar labels as string vectors is introduced in R2023b. Please refer to this release note.
Bar Charts: Specify bar labels as string vectors
When you create bar charts using the bar and barh functions, you can specify the bar labels as string vectors. The bar tick labels appear in the order you specify them.
Unfortunately, newly introduced features that are not bug fixes will not be backported to previous releases.
Julian
1
Publicación
1
Responder

Etiquetas

Aún no se han introducido etiquetas.