Home > front end >  How to have diferent markers and line styles while plotting same variable from multiple data files?
How to have diferent markers and line styles while plotting same variable from multiple data files?

Time:09-08

How can I have diferent markers or line styles when I am plotting same variable from 8 diferent data files in one figure? I have got my code that reads multiple excel files and it is perfectly fine with plotting the variable I call for from all 8 diferent excel files. Although I already have the plot with different colors that I have defined. However, somehow, I cannot define any marker or diferent Line Styles. I have attached my plotting codes below; please also see the figure

ax = gca;
grid on;
hold on
plot(Pin_dBm,Pout_Meas_dbm,"LineWidth",2)
%ax.LineStyleOrder={'-o','- ','-*','-x','-s','-d','-v','->'};
ax.ColorOrder=[1 0 0; 1 0 1; 0 1 0; 0.4660 0.6740 0.1880; 0 0 1; 0.3010 0.7450 0.9330; 0.8500 0.3250 0.0980; 0.9290 0.6940 0.1250]
ylabel('Output Power [dBm]','Color','K')
xlabel('Input Power [dBm]')
title('Output Power comparison - ON mode (0V)', 'Color', 'k')
legend('3F50Sa1','3F100Sa1', '5F50Sa1','5F100Sa1','7F50Sa1','7F100Sa1','9F50Sa1','9F100Sa1','location', 'bestoutside')

CodePudding user response:

To change trace (or marker) properties you have to use the plot handle, not the figure handle, to change line properties like LineWidth and Color.

To grab the plot handle you have to plot like this

hf1=figure(1)
ax = gca;
grid on;
hp1=plot(Pin_dBm,Pout_Meas_dbm)
hp1.LineWidth=2
hp1.Color='r'   % red

..

hf1 is the figure handle, not the trace or curve or graph handle.

The figure is the frame containing traces.

You don't have to, this is ok

hf1=figure

but it's good practice to number figures figure(n) as soon as generated, it helps reading code if later on someone has to findout what figure handle belongs to what figure.

now you tell the graph container, the figure with handle hf1 not to remove the 1st trace regardless of what you plot next:

hold(ax1,'on')

and now, with a for loop or one by one, or in any other way you choose, you can add more traces onto same figures changing the properties you choose using a different plot handle

hp2=plot(Pin_dBm2,Pout_Meas_dbm2)
hp2.LineWidth=1.5
hp1.Color='b'   % blue

..

and as you mention in your question you can send the same variable updated with different input data or file

update_Pin_dBm;
update_Pout_Meas_dbm;

If you do not update Pin_dBm and-or Pout_Meas_dbm the next plot with different properties may be identical or similar and overlap the previous trace.

hp3=plot(Pin_dBm,Pout_Meas_dbm)
hp3.LineWidth=1
hp1.Color=[0 1 1]    % cyan

The figure handle hf1 could still be used to change trace properties, because as the container to the plot, has as children property the handle to the plot. But no one uses what is otherwise a rather long Java-like expression

Note: The term marker is generally used, not for the graph line, the plot, but for the pointers on the graph line that scopes and also MATLAB allows to put, to read a particular (x,y).

If you find this answer useful, would you please be so kind to accept it? Thanks for reading my answer.

  • Related