Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Changing Line Properties

This example shows how to get properties of a line in MATLAB® and change line property values to customize your plot.

Line Objects

There are several ways to create a line object in MATLAB. One way is to use the plot command. You can get the line object created by the plot command by using an output argument. The display of the line object, p, shows the most commonly used line properties, such as Color, LineStyle, and Marker.

x = 0:0.2:10;
y = besselj(0, x);

figure
p = plot(x,y)
p = 
  Line with properties:

              Color: [0 0.4470 0.7410]
          LineStyle: '-'
          LineWidth: 0.5000
             Marker: 'none'
         MarkerSize: 6
    MarkerFaceColor: 'none'
              XData: [1×51 double]
              YData: [1×51 double]
              ZData: [1×0 double]

  Show all properties

Get Individual Line Properties

To access individual properties, use dot notation syntax object.PropertyName. For example, the following command returns the LineWidth property of the line.

p.LineWidth
ans = 0.5000

Change Line Properties

To customize the look of your plot, change line properties using dot notation.

p.Color = [1 0 0];              % set line color to red
p.LineStyle = '--';             % set line to be dashed
p.Marker = 'square';            % use square markers
p.MarkerEdgeColor = [0 0 1];    % set marker color to blue

Get All Line Properties

Graphics objects in MATLAB have many properties. To see all the properties of a line, use the get command.

get(p)
    AlignVertexCenters: 'off'
            Annotation: [1×1 matlab.graphics.eventdata.Annotation]
          BeingDeleted: 'off'
            BusyAction: 'queue'
         ButtonDownFcn: ''
              Children: [0×0 GraphicsPlaceholder]
              Clipping: 'on'
                 Color: [1 0 0]
             CreateFcn: ''
             DeleteFcn: ''
           DisplayName: ''
      HandleVisibility: 'on'
               HitTest: 'on'
         Interruptible: 'on'
              LineJoin: 'round'
             LineStyle: '--'
             LineWidth: 0.5000
                Marker: 'square'
       MarkerEdgeColor: [0 0 1]
       MarkerFaceColor: 'none'
         MarkerIndices: [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51]
            MarkerSize: 6
                Parent: [1×1 Axes]
         PickableParts: 'visible'
              Selected: 'off'
    SelectionHighlight: 'on'
                   Tag: ''
                  Type: 'line'
         UIContextMenu: [0×0 GraphicsPlaceholder]
              UserData: []
               Visible: 'on'
                 XData: [1×51 double]
             XDataMode: 'manual'
           XDataSource: ''
                 YData: [1×51 double]
           YDataSource: ''
                 ZData: [1×0 double]
           ZDataSource: ''
Was this topic helpful?