Heatmap labels based on another matrix
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hi
Im trying to get the heatmap function to work with my data. I want to show a different matrix of data as 'text' labels (numbers) on top of my heatmap, but I can't find how to link the new matrix to the heatmap function. I already found the following tutorial, but it doesnt work. It doesnt know 'labels_small'.
I know I have to convert the matrix to a cell with strings:
% matrix for heatmap [2x6]
thermala;
% additional matrix for 'text' labels
c_small = [1 2 3 4 5 6;
1 2 3 4 5 6];
c_label = sprintfc('%d',c_small);
heatmap(thermala);
Thank you in advance.
채택된 답변
dpb
2018년 4월 3일
1 개 추천
See the examples; you didn't call it with anything excepting the data array so it can't "know" anything about labels...
댓글 수: 17
dpb
2018년 4월 3일
-Joris Answer moved to Comment--dpb-
Thanks. Yes I know. I tried the format from the tutorial but it doesn’t know the expression labels_small. I want to know what I have to add to the function heatmap() to call the new matrix.
One example syntax is:
heatmap(spreads_small, labels_small, labels_small, '$%0.2f', 'TickAngle', 45);
All the arguments are arrays either from the input after executing
load heatmapData
or created therefrom.
You didn't include anything in the call excepting thermala in anything you've shown. You'll have to create variables for each input argument you want to use and pass them as do the examples.
I suspect if you go back and work through the examples sequentially as they're given you'll get a better understanding of how it works; I've never seen it before now but I'm certain each of those arguments is an input array and if you build and pass the equivalent it'll probably work as advertised.
Joris Puttenstein
2018년 4월 4일
편집: Joris Puttenstein
2018년 4월 4일
I totally agree with you. Besides the fact I already went through the tutorial. I understand I have to create all the variables for each input argument, but I don't fully understand the format of the labels.
%%Heatmap tutorial
heatmapData = [1 2 3 4 5 6;
6 5 4 3 2 1];
labels = [1 2 3 4 5 6;
6 5 4 3 2 1];
labels_small = sprintfc('%d',labels);
clf
heatmap(heatmapData,1:6,labels_small)
After I get this error code:
Error using heatmap (line 53)
Arguments must be a table followed by 2 table subscripts, a 2-dimensional numeric matrix, or 2 vectors followed by a 2-dimensional numeric matrix.
Error in heatmap_tutorial (line 12)
heatmap(heatmapData,1:6,labels_small)__
What am I doing wrong?
That's an array followed by a vector and a 2D character array...
Huh. I thunk before it was a FileExchange submittal; now I see there was a heatmap function introduced in R2017 (which I've not installed as yet). Is this what you've got?
Perhaps reading the direct doc may make more sense than the help...I see it is table -aware as well as data array.
What does
which heatmap
return on your system; which release?
I created a heatmap based on a matrix, not a table. And that should be supported (see direct doc.).
I've installed Matlab R2018a.
Oh...thanks, TMW! :(
Reading the doc more closely, they reordered inputs for array data as opposed to table--
h = heatmap(tbl,xvar,yvar)
h = heatmap(tbl,xvar,yvar,'ColorVariable',cvar)
the tbl is first but for cdata,
h = heatmap(xvalues,yvalues,cdata)
if use more than one input argument. That's terrible UI design; I've noted they have become more and more prone to such foopahs over the last few years that nobody is paying attention to such during design reviews it appears in the mad rush to introduce new features every rollout. :(
>> which heatmap -all
/Applications/MATLAB_R2018a.app/toolbox/matlab/specgraph/heatmap.m
>>
dpb
2018년 4월 4일
See my amended on arguments order...comments passed in the ether and I edited previous when I realized what was going on.
Thanks for your reply. I made some progress. Managed to plot the heatmap with x- and y-axis labels using the correct format :-)
h = heatmap(xvalues,yvalues,heatmapData);
It is indeed not logical the format is so different from the heatmap based on a table. Still, it is not clear for me what format is used for text labels when using a matrix. I assume it is similar to the format of the axis labels?
dpb
2018년 4월 5일
Which text labels do you mean? There's a link to the complete set of heatmap object properties that takes you to <heatmapchart-properties> that describes every available property.
I am trying to mimic this passage from the tutorial:
A completely different matrix of data can be shown as text labels on top of the original heatmap, enabling you to overlay another dataset
% Convert matrix c_small into a cell array of formatted strings
clabel = arrayfun(@(x){sprintf('%0.2f',x)}, c_small);
clf
heatmap(spreads_small, labels_small, labels_small, clabel, 'TickAngle', 45);
Can only guess; that syntax with four arguments other than named ones isn't shown in the documentation. The previous examples all seemed to be using the table which had to have the data array first while you're using an array in which it is in the third position; you can try adding it as
heatmap(x,y,data,labels)
or
heatmap(x,y,labels,data)
One guess, maybe they haven't done enough testing for cases other than using a table object and it just won't work with an array; it is a very convoluted set of inputs to parse; wouldn't surprise me a bit if there are still bugs what with it being so new.
Only other suggestion I'd have would be to convert your array to a table and try that route mimicking the example entirely in form but only with different data and see if that works.
Other than that, try reading the m-file and see if there are enough comments in the input parsing to figure out the order in which those inputs are expected if, indeed, the case is handled for array input.
Failing any/all of those, submit a bug report/service request for support.
Many thanks for your help. I will trial-and-error some more :-) Heatmap (in this stage) seems more like a beta-like feature.
dpb
2018년 4월 10일
Are you sure you do have the supplied version in R2018 and not the FEX version I also first found per Walter's comment? That could be a difference if so.
Ah I see now... In the Mathworks version I don't see the option with text labels on top of a Heatmap listed. So I think the option is exclusively for FEX? Anyhow, I found another way to display the information I initially wanted to.
dpb
2018년 4월 10일
Probably the difference, yes. You could probably have both if you were to make a slight rename of the FEX version or explicitly call the one desired if it has features you'd like...or, I presume you just text ed over the existing which is probably almost as simple.
@Joris Puttenstein I would like to know how you finally managed to display information on the heatmap.
Thnak you in advance
추가 답변 (1개)
Walter Roberson
2018년 4월 8일
0 개 추천
The heatmap function you are looking at is a file exchange contribution, not the same as the Mathworks heatmap function.
카테고리
도움말 센터 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
