Custom Plot with matlab
2 次查看(过去 30 天)
显示 更早的评论
I need to draw a custom plot with in Matlab, actually I will combine 4 different graph in one, with the following scenario Let say, I run an application for 4 times, the values goes to X axis will always be same, so for each run, x1=x2=x3=x4=[1 2 3 4];
For every x point there will be a y point, an element of set A=('a','b','c'),
Let say for each run the corresponding Y values are: y 1=['a' 'b' 'a' 'c']; y2=['a' 'a' 'b' 'c']; y3=['c' 'a' 'a' 'a']; and y4=['a' 'b' 'c' 'a']; with these values I want to draw a figure which combines all 4 runs in one chart. I want to represent the Y values as a 1 unit tall (actually its height is not that much matter) coloured vertical line, instead of just points. The following image demonstrated the figure I want to draw, anyone knows a way to achieve this? Thanks
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/163864/image.png)
0 个评论
采纳的回答
KSSV
2016-5-10
clc; clear all ;
% Set colors
a = 'g' ; b = 'r' ; c = 'y' ;
c1 = [{a} {b} {a} {c}] ;
c2 = [{a} {b} {b} {c}] ;
c3 = [{c} {a} {a} {a}] ;
c4 = [{a} {b} {c} {a}] ;
c = [c1 ; c2 ; c3; c4] ;
% Make grid
x = linspace(0,1,5) ;
y = linspace(0,1,5) ;
[X,Y] = meshgrid(x,y) ;
% Plot
figure
pcolor(X,Y,NaN(size(X)))
hold on
for i = 1:4
for j = 1:4
plot([X(i,j),X(i+1,j)],[Y(i,j),Y(i+1,j)],c{i,j},'linewidth',5)
end
end
axis off
xlim([x(1) x(end-1)])
0 个评论
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!