Changing area fill color above and below X-Axis, using drawnow

3 views (last 30 days)
I have a GUI set up that loads a data file, and when a pushbutton is pressed, the data is manipulated and plotted using drawnow. I calculate the integral for the curve continuously and update the number, however I also want to fill in the area under the curve in the plot. The data goes above and below the x-axis, so I'd like to have it fill in, for example, red below the x-axis and green above the axis. What I have tried to do is the following:
plot(handles.openaxes, Position(iz),Torque(iz),Position(first_turn:iz),Torque(first_turn:iz));
if Torque(iz)<0;
area(handles.openaxes, Position(first_turn:iz), Torque(first_turn:iz), 'FaceColor', [1 0 0]);
elseif Torque(iz)>0;
area(handles.openaxes, Position(first_turn:iz), Torque(first_turn:iz), 'FaceColor', [0 1 0]);
end
drawnow;
pause(0.1);(0.1);
This does start off with the right color and does switch upon crossing over the x-axis, however when it switches over, the entire plot becomes that color, not just the section I want. Any suggestions using area, patch, etc? Thanks for your help
Edit: Here is an image of the graph. The left section (-60 to -50 degrees) is what I want to show up read, as the torque is below zero.

Answers (0)

Community Treasure Hunt

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

Start Hunting!