Revert y-axis order in BarPlot
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Edoardo Taccaliti
el 16 de En. de 2024
Editada: Dyuman Joshi
el 16 de En. de 2024
I would like to revert the y-axis order of the plot , in such a way to have the most frequent element on top (close the y upper limit) and the less frequent (close to the x-sxis)
x = {'Breast' 'Colorectal' 'Lung\_NonSmallCell' 'Prostate' 'Skin\_Melanoma' 'Pancreas' 'Liver' 'Gastroesophageal' 'Ovarian' 'Kidney\_ClearCell' 'Lymphoid' 'Urothelial' 'CNS\_Medullo' 'CNS\_Glioma' 'Sarcoma\_Other' 'NET\_Pancreas' 'Biliary' 'HeadAndNeck\_Other' 'Uterus' 'Thyroid' 'Sarcoma\_GIST' 'Sarcoma\_Leiomyo' 'Cervix' 'CNS\_PiloAstro' 'NET\_Gastrointestinal' 'Lung\_SmallCell' 'Sarcoma\_Osteo' 'Kidney\_Chromophobe' 'Sarcoma\_Lipo' 'Mesothelium' 'HeadAndNeck\_SalivaryGland' 'Myeloid' 'Kidney\_Papillary' 'NET\_Lung' 'Skin\_Carcinoma'};
updatedStrings = strrep(x, '''', '"');
y = [996 710 588 560 406 347 340 328 284 237 218 200 138 131 131 119 114 91 75 67 67 64 59 58 54 53 44 43 42 41 34 34 32 26 25];
barh(x,y)
width = 1000; % Set the width in pixels
height = 900; % Set the height in pixels
set(gcf, 'Position', [100, 100, width, height]);
0 comentarios
Respuesta aceptada
Dyuman Joshi
el 16 de En. de 2024
Editada: Dyuman Joshi
el 16 de En. de 2024
There are multiple ways to do that.
One simple way is reverse the Y-axis direction (assuming the data is originally sorted descendingly) -
x = {'Breast' 'Colorectal' 'Lung\_NonSmallCell' 'Prostate' 'Skin\_Melanoma' 'Pancreas' 'Liver' 'Gastroesophageal' 'Ovarian' 'Kidney\_ClearCell' 'Lymphoid' 'Urothelial' 'CNS\_Medullo' 'CNS\_Glioma' 'Sarcoma\_Other' 'NET\_Pancreas' 'Biliary' 'HeadAndNeck\_Other' 'Uterus' 'Thyroid' 'Sarcoma\_GIST' 'Sarcoma\_Leiomyo' 'Cervix' 'CNS\_PiloAstro' 'NET\_Gastrointestinal' 'Lung\_SmallCell' 'Sarcoma\_Osteo' 'Kidney\_Chromophobe' 'Sarcoma\_Lipo' 'Mesothelium' 'HeadAndNeck\_SalivaryGland' 'Myeloid' 'Kidney\_Papillary' 'NET\_Lung' 'Skin\_Carcinoma'};
updatedStrings = strrep(x, '''', '"');
y = [996 710 588 560 406 347 340 328 284 237 218 200 138 131 131 119 114 91 75 67 67 64 59 58 54 53 44 43 42 41 34 34 32 26 25];
barh(x,y)
width = 1000; % Set the width in pixels
height = 900; % Set the height in pixels
set(gcf, 'Position', [100, 100, width, height]);
%Get the current axes
ax = gca;
%Reverse the y-axis direction
ax.YDir = 'reverse';
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Color and Styling en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

