Plotyy - Managing the colors of y-labels

4 visualizaciones (últimos 30 días)
Berk
Berk el 5 de Oct. de 2012
Hi,
I made the following plot using plotyy: <https://dl.dropbox.com/u/47922417/capture.jpg>
My questions are:
1. How can I make the first y-plot black (tick labels and the axis) and the second y-plot red?
2. How can I make the second y-plot's ticklabels discrete numbers? i.e. I do not want to show 0.5 and 1.5?
I have used the following code:
[AX,H1,H2] = plotyy(x,observed,x,capture,'plot', 'stem');
set(H1, 'Color', 'k');
set(H2, 'Color', 'r');
set(H1,'LineStyle','-', 'LineWidth', lineWidth,'DisplayName', 'Threshold');
set(H2,'LineStyle',':', 'LineWidth', lineWidth-1, 'DisplayName', 'Capture Rate');
h = [H1 H2];
set(AX,'XTick',1:aralik:lengthTime, 'FontSize', 32);
set(AX,'Xticklabel',' ');
set(AX,'XTickLabel',times);
%set(gca,'FontSize',34,'LineWidth',lineWidth);
h_xlabel = get(gca,'XLabel');
set(get(AX(1), 'Ylabel'),'String','Journey Time (min)', 'FontSize',axisSize, 'Color', 'k' );
set(get(AX(2),'Ylabel'),'String','Capture Rate', 'FontSize',axisSize, 'Color', 'r');
set(h_xlabel,'FontSize',axisSize);
legend(h);

Respuesta aceptada

Seth DeLand
Seth DeLand el 5 de Oct. de 2012
For (1) you can set the YColor property of each of the axes, for example:
set(AX(1),'YColor','k');
For (2), if you just want to get rid of 0.5 and 1.5 in this specific application, you can just set the YTick's to be 0:2
set(AX(2),'YTick',0:2)
If the range is going to change based on the data you're using, you can write some code that creates the YTick's based on the current axes limits. You could get the axes limits:
ylims = get(AX(2),'YLim');
and then figure out what values you wanted to show based on those limits.

Más respuestas (1)

Image Analyst
Image Analyst el 5 de Oct. de 2012
By the way, a nice improvement in R2012b is the ability to specify the ColorOrder property for each axes. It's a property in GUIDE and you just type in the color values you want each of your curves to take in that particular axes. It's a lot more convenient than before where ColorOrder was a global property and it was tricky to change.

Categorías

Más información sobre Two y-axis en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by