简体   繁体   English

绘图直方图(更改轴)

[英]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. 我有n * 2矩阵,例如矩阵A.第一列是一些索引,第二列是直方图。我想只显示非零直方图,所以,我过滤了A并删除了直方图为零的索引。 I use 我用

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

I didn't use excel. 我没有使用excel。 How can I plot it in excel? 我怎样才能在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) 这是我的数据(所以我想只显示这个矩阵的元素,但是如图所示,它显示从零到x轴的所有索引,我想只显示x轴中非零值的索引)

    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? 它具有非常糟糕的可视化。在matlab中是否可能,或者我应该使用其他软件? 我的数据

The result of Roney answer in my data. Roney的结果在我的数据中回答。 (I want the real label from my data below each bar in x axis.) (我希望我的数据中的真实标签位于x轴的每个条形下方。)

鲁尼回答的结果

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: 对于您的数据,结果将是:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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