legend pie chart

Hi i'm new to matlab and i have a question. for example if i have a vector with some ascii numbers, like
x=[65 65 67 68 68 68 68]
and i then want to draw a pie chart with the most frequent letter.
x=[65 65 67 68 68 68 68]
char(x)
y=unique(x)
counts=histc(x,y)
pie(counts,cellstr(num2str(counts(:))))
but my problem is that i want to have a legend witch will say what letter the different coulors represents, is that possible?

1 件のコメント

the cyclist
the cyclist 2012 年 1 月 19 日
Really an aside to your question, but you would probably want to use hist() rather than hist(), because you are specifying the bins, not the edges between the bins.
Also, I would recommend against a pie chart here. A bar chart will most likely allow the consumer to better judge the relative letter frequency.

サインインしてコメントする。

 採用された回答

Sean de Wolski
Sean de Wolski 2012 年 1 月 19 日

0 投票

Like this?
x=[65 65 67 68 68 68 68];
y=unique(x);
counts=histc(x,y);
pie(counts,cellstr(char((y')))')
Note transpose for num2str()

11 件のコメント

the cyclist
the cyclist 2012 年 1 月 19 日
Guessing maybe you want char(y) in the last line:
pie(counts,cellstr(num2str(char(y)'))')
franz
franz 2012 年 1 月 19 日
yes, exactly but I want to put up a legend that shows what letter the pie slices represents. like (68 would represent the letter D etc..)
Sean de Wolski
Sean de Wolski 2012 年 1 月 19 日
pie(counts,cellstr(char((y')))')
franz
franz 2012 年 1 月 19 日
So i still want the pie chart to say that it's 4x the number 68, but maybe have something in the corner of the chart that shows what the represent
franz
franz 2012 年 1 月 19 日
pie(counts,cellstr(char((y')))')
that would work with this example , but what if i have slices that are very close to each other then i would like to tell them apart and know how many numbers the slice represent. that's why I would like to have something that's outside of the pie in the corner of something
franz
franz 2012 年 1 月 19 日
or*
franz
franz 2012 年 1 月 19 日
Do you understand what I mean?
Sean de Wolski
Sean de Wolski 2012 年 1 月 19 日
like a legend? I'm liking cyclist's bar idea.
franz
franz 2012 年 1 月 19 日
yes, a legend exactly :P
Sean de Wolski
Sean de Wolski 2012 年 1 月 19 日
legend(cellstr(char((y')))')
franz
franz 2012 年 1 月 19 日
Yes that worked thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by