why is the color bar disrupting my GUI output??

1 view (last 30 days)
I am making a GUI with matlab. I have 4 axes each displaying a figure that is generated from a script, that has input from the user through a drop-down menu. though as the user clicks for the first time the GUI seems to work perfectly, while if the user chooses a second selection axes3 disappears.
After looking into the code I figured out the piece of code that is causing the trouble:
axes(handles.axes3);
y1 = 1:10;
[AX A B]=plotyy(Data_last_values(:,9),Data_last_values(:,6),Data_last_values(:,9),Data_last_values(:,8), @(x, y) scatter(x, y, [], Data_last_values(:,5)));%-> volumetric mass flow is used in the color bar
colormap(jet(20));
h=colorbar;
ylabel(AX(1), 'T_{in} [C]');
ylabel(AX(2), 'DT [C]');
xlabel('Q_{out} [W]')
ylabel(h, 'Volumetric Flow [Lt/min]')
title('figure 1 - Heat Exchanger HEX')
grid minor
I noticed that if I comment out the colorbar everything works perfectly, or replace the plotyy with scatter. The plot that I would like to make is a double yy scatter plot with a colorbar.
Any help would be super aprciated !! :)

Answers (1)

Walter Roberson
Walter Roberson on 26 Aug 2015
Remember that plotyy() creates a new axes for the second y. That axes might or might not be the current axes after the plotyy() call. colorbar() by default works on the current axes.
You should be calling colorbar with the axes you want it to be associated with.
Note: before R2014b, colorbar creates an axes itself, and that axes could become the current axes too. From R2014b onwards, colorbar creates a colorbar object rather than a new axes.

Categories

Find more on Two y-axis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!