How to add a verteical pad obove and below the curve and graph style and color displays?

Hello,
I have two questions and the data is attached to the question:
Q1) Lest hand side code is for the figure on right hand side. How I can the color of each curve and curve style (dotted, asterisk, etc.) by myself in the code instead of MATLAB is chossing automatically?
Q2) In the figure on right hand side, qp at various f are plotted against VD. I have attached a data having VD and one of qp curve. the qp curves not of same length of VD. I want to add a pad above and below the qp curves such that it becomes equal to VD. The pad values should be between 0.001 to 0.002. How I can do it?

8 Comments

hi
it would be good if post the code instead of a picture of it (if you want us to help you)
@Mathieu NOE here is code
figure(1),
hold on
for kk = 1:10:600
plot(Inv_Q(:,kk),VD, 'DisplayName',sprintf('f = %d',f(kk)))
end
hold off
grid
legend('Location','best'); set(gca, 'ydir', 'reverse');
xlim([0 3.0e-2]); ylim([1.8879e+03 2.1313e+03]);
xlabel('qp'); ylabel('VD');
thanks !
but in the mean time have yu tried the solution suggested by @Hiro ?
your mat file is missing Inv_Q data
error message :
Unrecognized function or variable 'Inv_Q'.
Error in nisar (line 7)
plot(Inv_Q(:,kk),VD, 'DisplayName',sprintf('f = %d',f(kk)))
>> whos
Name Size Bytes Class Attributes
VD1 115x1 920 double
qp 24x1 192 double
according to your code Inv_Q should be a 2D array , so I cannot use qp (1D)
size mismatch
FYI, a few options I tried to change automatically colors and linestyles (if that is ok for you) inside your loop
  • had to modify the plot code as for the time being I cannot use the provided x, y data
  • used some Filexchange submissions to get to this result
clc
% load('testdata.mat')
%% define your custom color order
% option 1 : manually : possible but takes time
% colors = [0 0 1;...
% 0 1 0;...
% 1 0 0;...
% 0 1 1;...
% 1 0 1;...
% 1 0.69 0.39;...
% 0.6 0.2 0;...
% 0 0.75 0.75;...
% 0.22 0.44 0.34;...
% 0.32 0.19 0.19]; %10x3 RGB array
% % or based on existing color maps
% colors = jet(60);
% or this
% % https://fr.mathworks.com/matlabcentral/fileexchange/42673-beautiful-and-distinguishable-line-colors-colormap
% colors = linspecer(60);
% even better :
func = @(x) colorspace('RGB->Lab',x); % https://fr.mathworks.com/matlabcentral/fileexchange/28790-colorspace-transformations
colors = distinguishable_colors(60,{'w','k'},func); % https://fr.mathworks.com/matlabcentral/fileexchange/29702-generate-maximally-perceptually-distinct-colors
%% define line styles and loop over them
linS = {'-','--',':','-.'};
figure(1),
hold on
c = 0;
cc = c;
for kk = 1:10:600
c= c+1;
cc = cc+1;
if cc>length(linS)
cc = 1 ; % restart from 1
end
% plot(Inv_Q(:,kk),VD,'Color',colors(n,:), 'DisplayName',sprintf('f = %d',f(kk)))
plot(VD1 + 0.1*kk,VD1,'Color',colors(c,:),'linestyle',linS{cc}, 'DisplayName',sprintf('f = %d',kk))
% plot(qp(:,kk),VD1,'Color',colors(c,:),'linestyle',linS{cc}, 'DisplayName',sprintf('f = %d',kk))
end
hold off
grid
legend('Location','best'); set(gca, 'ydir', 'reverse');
% xlim([0 3.0e-2]); ylim([1.8879e+03 2.1313e+03]);
xlabel('qp'); ylabel('VD');

Sign in to comment.

Answers (2)

Solution 1:
You can control the order of color by using colororder.
Also, you can specify the line markers by like this.
Solution 2:
How about re-sampling the VD with interp1 so you can have the identical length for that vector?

1 Comment

Thank you for the comments,
In the figure code, it is loop here so how to specify the colororder or markers is not working
figure(1),
hold on
for kk = 1:10:600
plot(Inv_Q(:,kk),VD, 'DisplayName',sprintf('f = %d',f(kk)))
end
hold off
grid
legend('Location','best'); set(gca, 'ydir', 'reverse');
xlim([0 3.0e-2]); ylim([1.8879e+03 2.1313e+03]);
xlabel('qp'); ylabel('VD');
2) I do not need to interploate, istead I need to add pad above and below until both matrices become equal.

Sign in to comment.

hello Nisar
this is my suggestion , and result
your last mat file does not contain the f data so I skipped that portion of code for the time being - should be fairly easy to reactivate it on your side
here a demo with a spacing of 5 netween succesive data (your original code was with a spacing of 10)
clc
load('testdata.mat')
[m,n] = size(Inv_Q);
%% define your custom color order
% option 1 : manually : possible but takes time and not flexible / robust
% colors = [0 0 1;...
% 0 1 0;...
% 1 0 0;...
% 0 1 1;...
% 1 0 1;...
% 1 0.69 0.39;...
% 0.6 0.2 0;...
% 0 0.75 0.75;...
% 0.22 0.44 0.34;...
% 0.32 0.19 0.19]; %10x3 RGB array
% % or based on existing color maps
% colors = jet(n);
% or this
% % https://fr.mathworks.com/matlabcentral/fileexchange/42673-beautiful-and-distinguishable-line-colors-colormap
% colors = linspecer(60);
% even better :
func = @(x) colorspace('RGB->Lab',x); % https://fr.mathworks.com/matlabcentral/fileexchange/28790-colorspace-transformations
colors = distinguishable_colors(n,{'w','k'},func); % https://fr.mathworks.com/matlabcentral/fileexchange/29702-generate-maximally-perceptually-distinct-colors
%% define line styles and loop over them
linS = {'-','--',':','-.'};
figure(1),
hold on
c = 0;
cc = c;
new_x = linspace(min(VD1),max(VD1),m);
for kk = 1:5:n
c= c+1;
cc = cc+1;
if cc>length(linS)
cc = 1 ; % restart from 1
end
plot(Inv_Q(:,kk),new_x,'Color',colors(c,:),'linestyle',linS{cc}); % plot(Inv_Q(:,kk),VD1, 'DisplayName',sprintf('f = %d',f(kk)))
leg_str{c} = (['Data ' num2str(kk)]);
end
hold off
grid
legend(leg_str,'Location','best'); set(gca, 'ydir', 'reverse');
xlim([0 3.0e-2]); ylim([1.8879e+03 2.1313e+03]);
xlabel('qp'); ylabel('VD');

Categories

Asked:

on 1 Jun 2022

Answered:

on 3 Jun 2022

Community Treasure Hunt

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

Start Hunting!