Matlab : 히 스트, 플롯 및 메시에 대한 동일한 컬러 맵

Azial

매트릭스에 5 가지 주파수에 대한 데이터 세트가 있고 플롯, 히 스트 및 메시를 사용하여 설명하고 싶습니다. 그러나 각 플롯 유형은 서로 다른 컬러 맵을 사용하므로 (그림 참조) 모든 플롯에 대한 범례가 필요합니다.

모든 플롯 유형에 대해 동일한 컬러 맵을 설정하거나 각각에 대해 하나씩 지정하는 방법이 있습니까? 또 다른 이상한 점 : 예를 들어 그림 도구를 사용하여 히 스트에 대한 컬러 맵을 설정할 수 있지만 일반 plot. 메시의 경우 hold on루프 를 사용해야하는데 여기서 색상을 설정하는 것이 컬러 맵을 정의하는 것과 다른 것 같습니다.

여기에 이미지 설명 입력

편집하다:

다음은 최소한의 예입니다. 여전히 작동하지 않습니다. 아래 코드의 주석을 참조하십시오.

clear all;
close all;
clc;

% make up some data with the original format
freqLen = 5;
data = zeros(10, 3, 3, freqLen);
data(:, :, :, 1) = rand(10, 3, 3);
data(:, :, :, 2) = rand(10, 3, 3)+1;
data(:, :, :, 3) = rand(10, 3, 3)+2;
data(:, :, :, 4) = rand(10, 3, 3)+3;
data(:, :, :, 5) = rand(10, 3, 3)+4;
% reshape data so we get a vector for each frequency
dataF = reshape(data, [10*3*3, freqLen]);

% prepare colors for plot, try to get 5 colors over the range of colormap
% but I get wrong colors using both methods below!
%cols = colormap(jet);
%cols = cols(1:round(length(cols)/length(freqGHz)):end, :);
cols = jet(freqLen);

% plot samples in 3D
figure('Position', [0 0 1000 1000]);
subplot(211);
hold on;
for iF = 1:freqLen
    dataThisF = dataF(:, iF);
    data3D = reshape(dataThisF, [10*3, 3]);
    mesh(data3D);
    % try to give each "holded" mesh a different color. Not working!
    % after the loop, all meshes have the last color
    set(get(gca, 'child'), 'FaceColor', 'w', 'EdgeColor', cols(iF, :));
end
view(60, 20);

% plot samples
subplot(223);
hold on;
for iF = 1:freqLen
    % the loop is not avoidable
    % because matlab maps the colors wrong when plotting as a matrix
    % at least its not using the colormap colors
    plot(dataF(:, iF), 'Color', cols(iF, :));
end

% plot histogram
subplot(224);
% actually the only one which is working as intended, horray!
hist(dataF, 50);

여기에 이미지 설명 입력

How can I give a holded mesh a single color, different from the others? How can I map the correct jet colormap when plotting a matrix using simple line plot, or at least get 5 colors from the jet colormap (jet(5) give 5 different colors, but not from start to end)?

Hoki

What you are talking about is mainly the ColorOrder property (and not the colormap of the figure).

The link for the colororder given just above will explain you how to force Matlab to use a given set of colors for all the plots. It works perfectly fine for plot. You wouldn't need a loop, just define the DefaultColororder property of the figure before the plots then plot all your series in one single call, Matlab will assign the color of each plot according to the order you defined earlier.

For mesh and hist it is not that simple unfortunately, so you will have to run a loop to specify the color or each graphic object. To modify a graphic object property (like the color) after it has been created, you have to use the set method, or even the direct dot notation if you're using a Matlab version >= 2014b. For both methods you needs to have the handle of the graphic object, so usually the easiest when you know you'll need that is to retrieve the graphic object handle at the time of creation*.

*instead of dirty hack like get(gca, 'child'). This is quite prone to errors and as a matter of fact was wrong in your case. Your code wouldn't color properly because you were not getting the right graphic handle this way.

아래 코드는 모든 그래프를 플로팅하고 각 그래픽 객체의 핸들을 검색 한 다음 최종 루프에서 색상을 할당합니다.


%// Get a few colors
cols = jet(freqLen);

% plot samples in 3D
figure('Position', [0 0 1000 1000]);
set( gcf , 'DefaultAxesColorOrder',cols) %// set the line color order for this figure

subplot(2,1,1,'NextPlot','add');         %// 'NextPlot','add' == "hold on" ;
for iF = 1:freqLen
    dataThisF = dataF(:, iF);
    data3D = reshape(dataThisF, [10*3, 3]);
    h.mesh(iF) = mesh(data3D) ;         %// plot MESH and retrieve handles

    %// You can set the color here direct, or in the last final "coloring" loop
    %// set( h.mesh(iF) , 'FaceColor', 'w', 'EdgeColor', cols(iF, :));
end
view(60, 20);

%// plot samples
subplot(223);
h.plots = plot(dataF);                  %// plot LINES and retrieve handles

%// plot histogram
subplot(224);
[counts,centers] = hist(dataF, 50 ) ;   %// get the counts values for each series
h.hist = bar(centers,counts) ;          %// plot HISTOGRAM and retrieve handles

%// now color every series with the same color
for iF = 1:freqLen
    thisColor = cols(iF, :) ;
    set( h.mesh(iF)  , 'EdgeColor' , thisColor  , 'FaceColor', 'w' );
    set( h.hist(iF)  , 'EdgeColor' , thisColor  , 'FaceColor' , thisColor )
    %// this is actually redundant, the colors of the plots were already right from the
    %// beginning thanks to the "DefaultColorOrder" property we specified earlier
    set( h.plots(iF) , 'Color'     , thisColor ) 
end

다음 그림이 표시됩니다. colororder

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

히트 맵 MATLAB에 컬러 바 표시

분류에서Dev

r의 동일한 플롯에 분산 및 히스토그램

분류에서Dev

Python 히트 맵 플롯 컬러 바

분류에서Dev

마우스 클릭 데이터에 대한 히트 맵과 같은 플롯

분류에서Dev

플롯 히트 맵 (R)에서 컬러 바 레이블 변경

분류에서Dev

MATLAB에서 여러 컬러 맵에 대한 컬러 바 표시

분류에서Dev

MATLAB : imagesc () 및 image ()는 동일한 컬러 맵을 다르게 표시합니다.

분류에서Dev

극좌표의 동일한 플롯에서 히트 맵과 결합 된 Gnuplot 표면 플롯

분류에서Dev

R의 통합 플롯에 대한 공통 행을 병합하는 히트 맵

분류에서Dev

동일한 플롯에서 나란히 표시되는 막대 그래프 및 꺾은 선형 차트

분류에서Dev

팬더, 플롯 히트 맵 및 행렬

분류에서Dev

밀도 히트 맵-이상한 스케일 및 디스플레이 문제, 제 생각에는?

분류에서Dev

히트 맵과 유사한 플롯에 예상 색상 열 추가 (출생)

분류에서Dev

2D 데이터 플로팅 : 다른 컬러 맵을 사용한 히트 맵

분류에서Dev

seaborn 히트 맵 컬러 맵

분류에서Dev

동일한 플롯에 정렬 된 원형 차트 및 막대 차트

분류에서Dev

Plotly.js에서 동일한 색상 스케일의 다양한 히트 맵

분류에서Dev

서브 플롯 및 주석이있는 히트 맵에서 xlim 설정

분류에서Dev

동일한 페이지에 ddply, ggplot 및 여러 플롯

분류에서Dev

Dash에서 여러 플롯에 대한 플롯 업데이트

분류에서Dev

일반 히트 맵이 작동하지만 플롯 팩토리 히트 맵이 플롯에서 실패합니다.

분류에서Dev

여러 플롯이 동일한 그림에 플롯 될 때 범례가 완전히 인쇄되지 않음

분류에서Dev

Scilab : 두 개의 서브 플롯에 대해 동일한 컬러 바

분류에서Dev

Matlab을 사용한 중앙 한계 정리에 대한 PDF 및 CDF 플롯

분류에서Dev

Python-3D 라인 플롯을위한 matplotlib의 컬러 맵

분류에서Dev

Octave의 각 서브 플롯에 대해 별도의 컬러 맵

분류에서Dev

R의 동일한 플롯에있는 두 개의 히스토그램

분류에서Dev

Pandas 데이터 프레임 히트 맵 디스플레이에서 중앙 발산 컬러 맵 사용

분류에서Dev

MATLAB에서 동일한 그래프에 여러 플롯을 만드는 방법

Related 관련 기사

  1. 1

    히트 맵 MATLAB에 컬러 바 표시

  2. 2

    r의 동일한 플롯에 분산 및 히스토그램

  3. 3

    Python 히트 맵 플롯 컬러 바

  4. 4

    마우스 클릭 데이터에 대한 히트 맵과 같은 플롯

  5. 5

    플롯 히트 맵 (R)에서 컬러 바 레이블 변경

  6. 6

    MATLAB에서 여러 컬러 맵에 대한 컬러 바 표시

  7. 7

    MATLAB : imagesc () 및 image ()는 동일한 컬러 맵을 다르게 표시합니다.

  8. 8

    극좌표의 동일한 플롯에서 히트 맵과 결합 된 Gnuplot 표면 플롯

  9. 9

    R의 통합 플롯에 대한 공통 행을 병합하는 히트 맵

  10. 10

    동일한 플롯에서 나란히 표시되는 막대 그래프 및 꺾은 선형 차트

  11. 11

    팬더, 플롯 히트 맵 및 행렬

  12. 12

    밀도 히트 맵-이상한 스케일 및 디스플레이 문제, 제 생각에는?

  13. 13

    히트 맵과 유사한 플롯에 예상 색상 열 추가 (출생)

  14. 14

    2D 데이터 플로팅 : 다른 컬러 맵을 사용한 히트 맵

  15. 15

    seaborn 히트 맵 컬러 맵

  16. 16

    동일한 플롯에 정렬 된 원형 차트 및 막대 차트

  17. 17

    Plotly.js에서 동일한 색상 스케일의 다양한 히트 맵

  18. 18

    서브 플롯 및 주석이있는 히트 맵에서 xlim 설정

  19. 19

    동일한 페이지에 ddply, ggplot 및 여러 플롯

  20. 20

    Dash에서 여러 플롯에 대한 플롯 업데이트

  21. 21

    일반 히트 맵이 작동하지만 플롯 팩토리 히트 맵이 플롯에서 실패합니다.

  22. 22

    여러 플롯이 동일한 그림에 플롯 될 때 범례가 완전히 인쇄되지 않음

  23. 23

    Scilab : 두 개의 서브 플롯에 대해 동일한 컬러 바

  24. 24

    Matlab을 사용한 중앙 한계 정리에 대한 PDF 및 CDF 플롯

  25. 25

    Python-3D 라인 플롯을위한 matplotlib의 컬러 맵

  26. 26

    Octave의 각 서브 플롯에 대해 별도의 컬러 맵

  27. 27

    R의 동일한 플롯에있는 두 개의 히스토그램

  28. 28

    Pandas 데이터 프레임 히트 맵 디스플레이에서 중앙 발산 컬러 맵 사용

  29. 29

    MATLAB에서 동일한 그래프에 여러 플롯을 만드는 방법

뜨겁다태그

보관