Filter löschen
Filter löschen

プロットをカラーマッ​プにしたがって重ね合​わせるには?

15 Ansichten (letzte 30 Tage)
Kanae
Kanae am 28 Mai 2024
Beantwortet: covao am 6 Jul. 2024 um 23:36
波形データをセル配列に格納し,波形ごとに少しずつ色を変えて描画したいです.
({1}に波形1の時系列データ,{2}に波形2の時系列データとして順に格納しています)
すべての波形プロットが完了したあとでcolororder(cool)など,所望のカラーマップを適用すると,指定のカラーマップで描画できているように見受けられるのですが,colorbarにはこの情報が反映されません.
以下のフォーラムに沿って指定しようとすると,「カラーマップに従って波形ごとに色を変える」ということ自体ができませんでした.
波形ごとに,任意のカラーマップに従って描画色を変え,そのcolorbarを横に表示するにはどのようにすればよいでしょうか?
https://jp.mathworks.com/matlabcentral/answers/1952534-

Antworten (1)

covao
covao am 6 Jul. 2024 um 23:36
ご質問のcolormapを用いて波形ごとに色を変えてプロットする例です。
(意図しているものとは異なるかもしれません。)
コードの作成に生成AIを用いています。
% Set the number of sample data
n = 10;
% Generate a cell array of waveform data (using random data as an example)
waveforms = arrayfun(@(x) rand(1, 100), 1:n, 'UniformOutput', false);
% Set colormap (select from the following)
cmap = cool(n); % Cool colormap
% cmap = hot(n); % Hot colormap
% cmap = jet(n); % Jet colormap
% cmap = parula(n); % Parula colormap
% cmap = hsv(n); % HSV colormap
% cmap = autumn(n); % Autumn colormap
% cmap = winter(n); % Winter colormap
% cmap = spring(n); % Spring colormap
% cmap = summer(n); % Summer colormap
% Set legend names
legendNames = arrayfun(@(x) sprintf('Wave %d', x), 1:n, 'UniformOutput', false);
% Plot
figure;
hold on;
for i = 1:n
plot(waveforms{i}, 'Color', cmap(i, :));
end
% Add colorbar
colormap(cmap);
c = colorbar('Ticks', linspace(0, 1, n), ...
'TickLabels', legendNames);
% Add title to the colorbar
c.Label.String = 'Waveforms';
% Set colorbar location to the right outside
set(c, 'Location', 'eastoutside')
% Set axis labels (if needed)
xlabel('Time');
ylabel('Amplitude');
title('Waveforms with Custom Colormap');
hold off;

Kategorien

Mehr zu カラーマップ finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!