【问题标题】:Unable to show 2 graphs with grid on in Matlab GUI无法在 Matlab GUI 中显示 2 个带有网格的图形
【发布时间】:2014-06-28 01:11:36
【问题描述】:

我正在 Matlab 中制作 GUI。这是我的代码示例

function plotResults(handles)

% Create output data plot in proper axes
plot(handles.outputAxes, handles.outputCurrentData, handles.outputVoltageData,'.-')
set(handles.outputAxes, 'XMinorTick', 'on')
grid on

% Create magnet data plot in proper axes
plot(handles.magnetAxes, handles.magnetCurrentData, handles.magnetVoltageData, '.-')
set(handles.magnetAxes, 'XMinorTick', 'on')
grid on

但是,只有第 2 个轴显示一个网格,第一个轴没有。谁能告诉我为什么?谢谢

【问题讨论】:

  • @GeoffHayes 谢谢 Geoff,成功了!

标签: matlab user-interface grid


【解决方案1】:

这是一种特殊的行为。我能够用一个简单的 GUI 重现它,无论我如何订购上述代码(magnetAxes 之前的outputAxes),始终是 magnetAxes 显示了网格,而另一个则将其删除(可能是因为我第二个添加了magentAxes 小部件?)。

grid on 语句仅为 当前轴 开启网格,因此可能部分混淆了 - magnetAxis 具有“焦点”,因此它使用网格更新,而另一个不是因为它从未设置为当前轴。

两种解决方案如下 - 指定您希望启用网格的轴

grid(handles.outputAxes,'on');  % replace grid on with this for the first axis
grid(handles.magnetAxes,'on');  % replace grid on with this for the second axis

或完全删除 grid on 语句,然后执行

set(handles.outputAxes, 'XMinorTick', 'on','XGrid','on','YGrid','on');
set(handles.magnetAxes, 'XMinorTick', 'on','XGrid','on','YGrid','on');

第三种选择是在调用grid on(即axes(handles.outputAxes);)之前手动设置当前轴。

【讨论】:

  • 这并不奇怪。 current axes 是最后创建或使用鼠标单击的坐标区。
猜你喜欢
  • 1970-01-01
  • 2013-09-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-24
  • 1970-01-01
  • 1970-01-01
  • 2020-12-04
相关资源
最近更新 更多