how to change the color of the coordinate in Plotyy?
2 次查看(过去 30 天)
显示 更早的评论
Hi all, Please is there any way to change the color of y coordinate in plotyy. Also can I place the plotyy in for loop. I wan to add more curves to the plot.
Thank you Aziz
1 个评论
Walter Roberson
2015-12-23
Is the question about the color of the lines that are drawn, or about the colors of the labels along the axes?
Note that plotyy is for the case where you need separate labeling for the ticks, such as if you were labeling a plot with frequency along the left and wavelength along the right. Because you run out of sides to label, you cannot just keep adding more axes. You might want to look at the File Exchange contribution plotyyy but more likely you just need regular plot() and legend()
回答(2 个)
Vidya Viswanathan
2015-12-23
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
figure;
colors=['r','b']; % defines two colors (one corresponding to sine signal and the other for cosine signal)
for i=1:2
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
end
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Two y-axis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!