필터 지우기
필터 지우기

Clarity when you have multiple plots

조회 수: 2 (최근 30일)
Raushan
Raushan 2022년 8월 30일
댓글: Raushan 2022년 9월 2일
Hey guys! I have one .csv file containing 8 columns. I want to plot 8th column (Time200) on x axis and remaining 7 columns on y axis. I did that but plots look messy, I mean its hard to interprate the difference among graphs. Is there any way to make these plots clear or interpratable. I will appreciate any kind of help. Thank you.

채택된 답변

Image Analyst
Image Analyst 2022년 8월 30일
편집: Image Analyst 2022년 9월 2일
How about this:
% Initialization Steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
data = importdata('Plotdata.csv');
timeData = data.data;
columnHeaders = data.colheaders;
[rows, columns] = size(timeData);
% Sort by column 8 in ascending order
timeData = sortrows(timeData, 8)
t = timeData(:, end); % Times are the last column.
% Make up colors for the plot lines
plotColors = jet(columns - 1);
% Plot columns 1 to columns-1
for col = 1 : columns - 1
y = timeData(:, col);
plot(t, y, '.-', 'Color', plotColors(col, :), 'LineWidth', 2, 'MarkerSize', 30);
hold on;
end
xlabel('Time', 'FontSize',fontSize);
ylabel('y', 'FontSize',fontSize);
grid on;
hold off;
legend(columnHeaders(1:end-1), 'Location', 'southwest')
[EDIT] plot with original data removed at poster's request.
  댓글 수: 3
Image Analyst
Image Analyst 2022년 9월 2일
As requested, I've changed my program to not use your data, which looked pretty generic by the way. I wrote a program to create some plots and run it with both unsorted times (like you have) and with the times sorted. The results are shown below:
% Demo by Image Analyst
% Initialization Steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
% data = importdata('Plotdata.csv');
% timeData = data.data;
[t, timeData, columnHeaders] = CreateSampleData();
% columnHeaders = data.colheaders;
[rows, columns] = size(timeData);
promptMessage = sprintf('Do you want to sort the times?');
titleBarCaption = 'Sort?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Yes', 'No', 'Quit', 'Yes');
if contains(buttonText, 'Quit', 'IgnoreCase', true)
return; % or break or continue.
elseif contains(buttonText, 'Yes', 'IgnoreCase', true)
% Sort time in ascending order
t = sort(t);
plotTitle = 'Using sorted times';
else
plotTitle = 'Using unsorted times';
end
% Make up colors for the plot lines
plotColors = jet(columns);
% Plot columns
for col = 1 : columns
y = timeData(:, col);
plot(t, y, '.-', 'Color', plotColors(col, :), 'LineWidth', 2, 'MarkerSize', 30);
hold on;
end
title(plotTitle, 'FontSize', fontSize);
xlabel('Time', 'FontSize',fontSize);
ylabel('y', 'FontSize',fontSize);
grid on;
hold off;
legend(columnHeaders(1:end), 'Location', 'southwest')
%=============================================================================================
function [t, timeData, columnHeaders] = CreateSampleData()
rows = 15;
columns = 8;
columnHeaders = cell(columns, 1);
baseCurve = linspace(0.17, 0.10, rows)';
t = 1 : rows;
% Scramble order of the times, like the original poster had.
randomOrder = randperm(length(t));
t = t(randomOrder);
% Add noise and lift
for col = 1 : columns
thisCol = baseCurve + .1 * col + 0.05 * rand(rows, 1);
timeData(:, col) = thisCol;
columnHeaders{col} = sprintf('Time %d', col);
end
end
Raushan
Raushan 2022년 9월 2일
Thank you very much sir! It helps me a lot.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by