轴上的反向 Y 轴

Reverse Y-Axis on Axes

我有一个 GUI window,上面有一个轴框,我想在使用绘图函数时反转此轴 1 框上的 Y 轴方向。当我尝试使用时,可以说:

set(axes1,'YDir','reverse');

我收到以下错误

Error using matlab.graphics.chart.primitive.Line/set
There is no YDir property on the Line class.

当我检查这个 axes1 的属性时,我得到

AlignVertexCenters: 'off'
            Annotation: [1x1 matlab.graphics.eventdata.Annotation]
          BeingDeleted: 'off'
            BusyAction: 'queue'
         ButtonDownFcn: ''
              Children: [0x0 GraphicsPlaceholder]
              Clipping: 'on'
                 Color: [1 0 0]
             CreateFcn: ''
             DeleteFcn: ''
           DisplayName: ''
      HandleVisibility: 'on'
               HitTest: 'on'
         Interruptible: 'on'
              LineJoin: 'round'
             LineStyle: '-'
             LineWidth: 1
                Marker: 'none'
       MarkerEdgeColor: 'auto'
       MarkerFaceColor: 'none'
            MarkerSize: 6
                Parent: [1x1 Axes]
         PickableParts: 'visible'
              Selected: 'off'
    SelectionHighlight: 'on'
                   Tag: ''
                  Type: 'line'
         UIContextMenu: [0x0 GraphicsPlaceholder]
              UserData: []
               Visible: 'on'
                 XData: [1x3937 double]
             XDataMode: 'manual'
           XDataSource: ''
                 YData: [1x3937 double]
           YDataSource: ''
                 ZData: [1x0 double]
           ZDataSource: ''

所以我尝试将 属性 检查器上的 YDir 从正常更改为反向,但没有成功。 我试过使用 flipud 它只是翻转了直线而不是 Y 轴上的值。

看来您所说的 axes1 实际上是一个 line 对象。您可以通过获取对象的 Type 属性 轻松检查这一点。

get(axes1, 'Type')

% Or in newer versions of MATLAB
class(axes1)

您需要在其 父轴 上设置 YDir。我们可以使用 ancestor 函数轻松获得它。

hax = ancestor(axes1, 'axes');
set(hax, 'YDir', 'reverse')

或更简单地针对您的具体情况:

set(axes1.Parent, 'YDir', 'reverse')

以后仔细阅读错误信息的全部内容。这里非常明确地表明您的命令不起作用,因为它是一行。