单击时显示轴 - matlab

show axes on click - matlab

我有一个列表框按钮,假设它包含 3 个选项:“1”“2”“3”。 我也有5轴。 选择“2”后,我会在这 5 个轴上绘制一些东西。 我想知道的是如何再制作 5 个仅在选择“3”时才会显示的轴。 我的意思是,用户将无法看到轴 6~10,直到他按下“3”,如果他按下“1”或“2”,那么用户将无法看到它们。

您可以将共享相同属性(即同时可见或不可见)的轴分组为 1 个变量(例如 TopAxesBottomAxes),从而更新它们的属性同时在 Listbox 回调中。

这是一个有 6 个轴的例子,3 个在顶部,3 个在底部。当用户选择“1”时,所有轴都可见。选择“2”时,只有顶部轴可见,选择“3”时,仅底部轴可见。这是带有屏幕截图的代码:

function ShowAxesGUI

clear
clc

hFig = figure('Position',[100 100 600 600]);

%// Create axes
handles.ax1 = axes('Position',[.1 .6 .2 .2]);
handles.ax2 = axes('Position',[.4 .6 .2 .2]);
handles.ax3 = axes('Position',[.7 .6 .2 .2]);

%// Group top axes together
handles.TopAxes= [handles.ax1;handles.ax2;handles.ax3];

handles.ax4 = axes('Position',[.1 .2 .2 .2]);
handles.ax5 = axes('Position',[.4 .2 .2 .2]);
handles.ax6 = axes('Position',[.7 .2 .2 .2]);

%// Group bottom axes together
handles.BottomAxes= [handles.ax4;handles.ax5;handles.ax6];

set(handles.BottomAxes,'Visible','off')

%//  Create listbox

handles.listbox1 = uicontrol('Style','list','Position',[50 520 60 60],'Value',1,'String',{'1';'2';'3'},'Callback',@(s,e) ListCallback);

guidata(hFig,handles)

    %// Listbox callback
    function ListCallback

        handles = guidata(hFig);

        %// Get the selected item in the listbox
        ListSelection = get(handles.listbox1,'Value');

        switch ListSelection

            case 1                
                set(handles.TopAxes,'Visible','on')
                set(handles.BottomAxes,'Visible','on')
            case 2
                set(handles.TopAxes,'Visible','on')
                set(handles.BottomAxes,'Visible','off')
            case 3
                set(handles.TopAxes,'Visible','off')
                set(handles.BottomAxes,'Visible','on')
        end

        guidata(hFig,handles)
    end
end

有 3 个不同的选项:

1)

2)

3)

就是这样。祝你好运!