how to change the color of the coordinate in Plotyy?
1 view (last 30 days)
Vidya Viswanathan on 23 Dec 2015
It is possible to change the color of the axes as well as the data points in a plot. The plot could have been generated using any of the functions used for creating graphs, such as, "plot", "plotyy", etc. As long as the axes handle is available, we can alter the properties of the plot programmatically. Consider the following code snippet that shows how "plotyy" can be used to plot multiple signals and how the color of the two axes can be altered:
%%Plots sine and cosine signals of two different frequencies on the same figure
freq=.1:0.1:.2; % defines two different frequencies
time_idx=0:0.01:10; % defines the time indices for the signals
colors=['r','b']; % defines two colors (one corresponding to sine signal and the other for cosine signal)
x=sin(2*pi*freq(i).*time_idx); % generates the sine signal
y=2.*cos(2*pi*freq(i).*time_idx); % generates the cosine signal
[Hax,Hl1,Hl2]=plotyy(time_idx,x,time_idx,y) % Hax contains both the axes handles,
%Hl1 has the handle for the sine plot,
%Hl2 has the handle for cosine plot
hold on % To display the plots corresponding to second frequency as well in the same figure
Hax(1).YColor='r'; % Alters the color of the first axis
Hax(1).YLabel.String='Sine plot'; % Adds a label to the first axis
Hax(2).YColor='b'; % Alters the color of the second axis
Hax(2).YLabel.String='Cosine plot'; % Adds a label to the second axis
Hl1.Color=colors(1); % Changes the color of the sine plot
Hl2.Color=colors(2); % Changes the color of the cosine plot
As an alternative, the properties of the figure can also be modified interactively from the figure window. In the "Figure" window, click on "View" and select "Plot Browser". The properties of the axes can be modified by double-clicking the corresponding axis. This opens the "Property Editor" window.
I hope this answers your query.