From: Thijs Aaten on 29 Dec 2009 14:42 How can I create a graph in matlab that displays a financial time series, but for each date I also have a binary variable (true/false). If the binary variable is true for lets say a month, I want that month to be shaded gray in the graph. The graph would then show the time series and vertical gray shaded areas/bars from top to bottom when the variable is true. Thanks for your help ! Thijs
From: ImageAnalyst on 29 Dec 2009 15:07 Thijs Aaten: I haven't done it before but you might try something similar to what I used to color different segments of a pie chart according to what I wanted. Get the handles to each bar with either bar() or findobj() to find handles to child objects of your bar chart - i.e. handles to individual bars. Then loop through them and when you find a bar that needs to be gray shaded (according to your criteria) then use the set() command and that bar's handle to set the color or facecolor to gray. Here's my pie chart coloring function for reference: %===================================================================== % If you apply a colormap, MATLAB has a "feature" where it applies the % colormap to ALL the axes on the figure, not just the current axes. So if % you apply a colormap to the current axes (your pie chart) thinking it % will affect only your pie chart, you will be surprised to find it affects % all other charts and images on the dialog box. To get around that, use % this function which the colors of the pie segments and does not affect % any other objects in the dialog box. You need to pass in % hPieComponentHandles which you get when you create the pie chart: % hPieComponentHandles = pie([Value1, Value2, Value3],{'Label 1','Label 2','Label 3'}); % Then make up your color map like this: % pieColorMap(1,:) = [.22 .71 .29]; % Color for segment 1. % pieColorMap(2,:) = [.25 .55 .79]; % Color for segment 2. % pieColorMap(3,:) = [.93 .11 .14]; % Color for segment 3. % and finally, call this function % SetPieChartColors(hPieComponentHandles, pieColorMap); function SetPieChartColors(hPieComponentHandles, PieSegmentColors) set(hPieComponentHandles(1),'FaceColor', PieSegmentColors(1,:)); set(hPieComponentHandles(3),'FaceColor', PieSegmentColors(2,:)); set(hPieComponentHandles(5),'FaceColor', PieSegmentColors(3,:)); return;
|
Pages: 1 Prev: Count ASCII value Next: Integer operands are required for colon operator when used as index |