Create histogram with rotated string labels in MATLAB -


i have matlab table following specification: first column property name , second times occurs. here complete csv-file data. excerpt:

rsa_with_rc4_128_sha,240 rsa_with_rc4_128_md5,184 rsa_with_aes_128_cbc_sha,464 ...  

now want plot histogram show frequency property names below. maybe looks (sorry crude drawing):

example

please don't take bars figuratively, sample show how want text labels below, grouping of bars not significant.

how can this?

at first, can read-in data table, convenient use. then, plot bars bar using data of second column of table, addressed t{:,2}. additional space on right side of plot can cropped manually setting xlim-property.

after that, construct text of labels. therefore want concatenate first column of table string-representation of number in second column of table. strcat can concatenation of cell array t{:,1} , cell array returned arrayfun , puts , between them specified.

now need set xtick...-properties desired result: xtick specifies position of ticks along x-axis. xticklabel defines text of labels @ before defined positions. xticklabelrotation can rotate label given amount in degrees. finally, ticklabelinterpreter set none prevent text after underscores subscripted.

here code that:

% read data table t = readtable('path_0.csv');  % draw bars figure; bar(1:size(t,1),t{:,2}); set(gca,'xlim',[0,size(t,1)+1]); grid on;  % change labels xlabels = strcat(t{:,1},',',arrayfun(@num2str,t{:,2},'uniformoutput',false)); set(gca,'xlim',[0,size(t,1)+1],...         'xtick',1:length(xlabels),...         'xticklabel',xlabels,...         'xticklabelrotation',45,...         'ticklabelinterpreter','none'); 

here produced figure: result


Popular posts from this blog

node.js - How do I prevent MongoDB replica set from querying the primary? -

Apache NiFi ExecuteScript: Groovy script to replace Json values via a mapping file -