简体   繁体   English

MATLAB。 饼图标签

[英]matlab. labels to a pie chart

I have a matrix X. In the first column there are 5 values which are integers from 0 to 4. In the second column there are values that I want to plot in a pie chart. 我有一个矩阵X。在第一列中有5个值,它们是0到4之间的整数。在第二列中,有一些要绘制在饼图中的值。 How can I label the values in X(:,2) with the corresponding values from X(:,1) in the pie chart? 如何用饼图中的X(:,1)中的相应值标记X(:,2)中的值?

From what I understand this might do the trick: 据我了解,这可能会解决问题:

clear all
clc

A = [0 3;1 1;2 5;3 6;4 5]; %// Generate dummy data

Labels = sprintfc('Row%d',A(:,1)+1) %// Generate appropriate labels and store in a cell array

Labels looks like this: 标签看起来像这样:

Labels = 

    'Row1'
    'Row2'
    'Row3'
    'Row4'
    'Row5'

and the pie chart: 和饼图:

pie(A(:,2),Labels)

在此处输入图片说明

Is this what you meant? 这是你的意思吗? You might want to take a look here for more info about pie charts and ways in which to customize labels. 您可能需要在此处查看有关饼图以及自定义标签的方法的更多信息。 For instance sprintf can be used to produce more complex labels. 例如, sprintf可用于产生更复杂的标签。 If you would like to know how please ask! 如果您想知道如何请询问!

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

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