简体   繁体   中英

Plot histogram(change axis)

I have n*2 matrix for example matrix A.First column is some index and the second one is the histogram.I want to visualise only the nonzero histogram,so, I filtered A and deleted the index with histogram zero. I use

 bar(A(:,1),A(:,2))

I didn't use excel. How can I plot it in excel?

This is my data (so I want to display only the elements of this matrix but as you see in figure it display all index from zero to end in x axis and I want to display only the index of nonzero values in x axis)

    1   0.0573770000000000
    2   0.622951000000000
    3   0.0819672000000000
    4   0.0491803000000000
    5   0.0409836000000000
    6   0.00819672000000000
    7   0.00819672000000000
    8   0.0163934000000000
    10  0.00819672000000000
    12  0.00819672000000000
    14  0.00819672000000000
    19  0.0163934000000000
    34  0.00819672000000000
    50  0.00819672000000000
    54  0.00819672000000000
    62  0.00819672000000000
    175 0.00819672000000000
    410 0.00819672000000000
   1178 0.00819672000000000
   1193 0.00819672000000000
   1669 0.00819672000000000

It has very bad visualisation.Is it possible in matlab or I should use another software? 我的数据

The result of Roney answer in my data. (I want the real label from my data below each bar in x axis.)

鲁尼回答的结果

Thanks

If you mean the you want the non-zero bars to be displayed without gaps between them for the zero values, you can do the following:

>> non_zero = A(:,2) ~= 0;
>> bar(A(non_zero,2))
>> set(gca, 'XTick', 1:sum(non_zero));    %New code.
>> set(gca, 'XTickLabel', num2str(A(non_zero,1)));

For say,

>> 
A = [
1 0.001
2 0.005
4 0
5 0.003
];

The resultant figure would be:

在此输入图像描述

For your data, the result would be:

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM