Display or hide axes grid lines (2024)

Display or hide axes grid lines

collapse all in page

Syntax

grid on

grid off

grid

grid minor

grid(visibility)

grid(target,___)

Description

example

grid on displays the major grid lines for the current axes returned by the gca command. Major grid lines extend from each tick mark.

example

grid off removes all grid lines from the current axes or chart.

grid toggles the visibility of the majorgrid lines.

example

grid minor toggles the visibility of the minor grid lines. Minor grid lines lie between the tick marks. Not all types of charts support minor grid lines.

grid(visibility) displays or hides the grid by specifying a visibility value. You can specify visibility as "on", "off", a logical value, or an OnOffSwitchState value.

example

grid(target,___) uses the axes or standalone visualization specified by target instead of the current axes. Specify target before all other arguments.

Examples

collapse all

Open Live Script

Display the grid lines for a sine plot.

x = linspace(0,10);y = sin(x);plot(x,y)grid on

Display or hide axes grid lines (1)

Remove Grid Lines

Open Live Script

Create a surface plot and remove the grid lines.

[X,Y,Z] = peaks; surf(X,Y,Z)grid off

Display or hide axes grid lines (2)

Display Major and Minor Grid Lines

Open Live Script

Display the major and minor grid lines for a sine plot.

x = linspace(0,10);y = sin(x);plot(x,y)grid ongrid minor

Display or hide axes grid lines (3)

Display Grid Lines on Specific Axes

Open Live Script

Starting in R2019b, you can display a tiling of plots using the tiledlayout and nexttile functions. Call the tiledlayout function to create a 2-by-1 tiled chart layout. Call the nexttile function to create the axes objects ax1 and ax2. Plot data into each axes. Then display grid lines in the bottom plot by passing ax2 to the grid function.

x = linspace(0,10);y1 = sin(x);y2 = sin(3*x);tiledlayout(2,1)% Top plotax1 = nexttile;plot(ax1,x,y1)% Bottom plotax2 = nexttile;plot(ax2,x,y2)grid(ax2,'on')

Display or hide axes grid lines (4)

Input Arguments

collapse all

visibilityGrid visibility
"on" | "off" | true or 1 | false or 0 | OnOffSwitchState value

Grid visibility, specified one of these values:

  • "on" or "off" — A value of "on" displays the grid, and "off" hides it. You can also specify the character vectors 'on' or 'off'.

  • Numeric or logical 1 (true) or 0 (false) — A value of 1 or true displays the grid, and 0 or false hides it. (since R2024a)

  • A matlab.lang.OnOffSwitchState value — A value of matlab.lang.OnOffSwitchState.on displays the grid, and matlab.lang.OnOffSwitchState.off hides it. (since R2024a)

targetTarget object
axes | standalone visualization | array of axes or standalone visualizations

Target object, specified as one of the following:

  • Any type of axes object: an Axes, PolarAxes, or GeographicAxes object.

  • A standalone visualization that has a GridVisible property. For example, a heatmap chart has a GridVisible property.

  • An array of axes or standalone visualizations that belong to the same class. To determine the class, use the class function.

If you do not specify the target, then the grid function affects the graphics object returned by the gca command.

Tips

  • When working with Cartesian axes, some axes propertiesaffect the appearance of the grid lines. This table lists a subsetof axes properties related to the grid lines.

    Axes PropertyDescription
    XTick, YTick, ZTickLocation of tick marks and major grid lines for each axis direction
    XGrid, YGrid, ZGridDisplay of major grid lines for each axis direction
    XMinorGrid, YMinorGrid, ZMinorGridDisplay of minor grid lines for each axis direction
    LineWidthLine width of grid lines, axes box outline, and tick marks
    GridLineStyleMajor grid line style
    MinorGridLineStyleMinor grid line style
    GridColorMajor grid line color
    MinorGridColorMinor grid line color
    GridAlphaMajor grid line transparency
    MinorGridAlphaMinor grid line transparency
    LayerLocation of grid lines in relation to the plotted data
  • When working with polar axes, some polar axes propertiesaffect the appearance of the grid lines. This table lists a subsetof polar axes properties related to the grid lines.

    PolarAxes PropertyDescription
    ThetaTick, RTickLocation of tick marks and major grid lines for each axis direction
    ThetaGrid, RGridDisplay of major grid lines for each axis direction
    ThetaMinorGrid, RMinorGridDisplay of minor grid lines for each axis direction
    LineWidthWidth of outline, tick marks, and grid lines
    GridLineStyleMajor grid line style
    MinorGridLineStyleMinor grid line style
    GridColorMajor grid line color
    MinorGridColorMinor grid line color
    GridAlphaMajor grid line transparency
    MinorGridAlphaMinor grid line transparency
    LayerLocation of grid lines in relation to the plotted data
  • When working with geographic axes, some geographic axes properties affect the appearance of the grid lines. This table lists a subset of geographic axes properties related to the grid lines. Note that GeographicAxes objects do not support minor grid lines.

    GeographicAxes PropertyDescription
    GridDisplay of latitude and longitude grid lines
    LineWidthLine width of grid lines, box outline, and tick marks
    GridLineStyleGrid line style
    GridColorColor of grid lines
    GridAlphaGrid line transparency

Algorithms

The grid function sets these graphics objectproperties to either 'on' or 'off':

  • XGrid, YGrid, and ZGrid when working with Cartesian Axes objects.

  • ThetaGrid and RGrid whenworking with PolarAxes objects.

  • Grid when working with GeographicAxes objects.

  • GridVisible when working with othertypes of graphics objects, such as a HeatmapChart object.

Version History

Introduced before R2006a

expand all

See Also

Functions

  • axis | box | title | xlabel | ylabel | legend

Properties

  • Axes Properties | PolarAxes Properties | GeographicAxes Properties

Classes

  • matlab.lang.OnOffSwitchState

Topics

  • Add Grid Lines and Edit Placement

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Display or hide axes grid lines (5)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

Contact your local office

Display or hide axes grid lines (2024)

FAQs

How do you display grid lines? ›

Select the worksheet. Click the Page Layout tab. To show gridlines: Under Gridlines, select the View check box. To hide gridlines: Under Gridlines, clear the View check box.

How can you show or hide the gridlines in an Excel worksheet? ›

To show the gridlines, in Excel, PowerPoint, or Word, click the View tab, and then check the Gridlines box. To hide the gridlines, clear the Gridlines check box.

Should plots have gridlines? ›

Grid lines are rarely needed in graphs to help readers assign accurate numeric values to the data; the approximate values that can be perceived without the aid of grid lines are almost always adequate.

How do I hide a grid line chart? ›

Hide chart gridlines
  1. Click anywhere on the chart in which you want to hide chart gridlines.
  2. On the Design tab, in the Chart Layouts group, click Add Chart Element, point to Gridlines, and then click the gridline option you want to hide. You can rest your mouse pointer over each option to preview the gridline display.

How do I hide gridlines? ›

You can either show or hide gridlines on a worksheet in Excel for the web. On the View tab, in the Show group, select the Gridlines check box to show gridlines, or clear the check box to hide them. Excel for the web works seamlessly with the Office desktop programs. Try or buy the latest version of Office now.

How do you display gridlines for the table? ›

Showing or hiding table gridlines shows or hides gridlines for every table in your document. Unlike table borders, you can't print table gridlines with your document. Click the table. Click the Table Layout tab, and then under Settings, click Gridlines.

How do I hide and display rows in Excel? ›

Just select the cell or cells, then go to Home, and in Cells group, click Format. Then under Visibility, point to Hide\Unhide, and then click Hide Rows or Hide Columns. This will hide the Rows or Columns of the selected cell or cells.

How to hide gridlines in sheets? ›

Navigate to View Menu

To remove gridlines in Google Sheets, start by opening your Google Sheet spreadsheet and clicking “View” from the menu bar. From the “View” menu, select “Show gridlines” option to uncheck it.

How do I remove grid lines in an Excel chart? ›

If you want to turn off your gridlines, open the Chart Elements window and uncheck the Gridlines option.

What is the purpose of grid lines? ›

Gridlines are horizontal and vertical lines that appear on a computer screen, spreadsheet, or graph to help users align and organize data or elements. They serve as visual guides to assist in accurately placing objects and understanding the structure of a document or interface.

Where should grid lines be placed? ›

Gridlines will typically align with the primary structural elements of a building, this provides a background map of known, source-of-truth points that all other elements in, and around the building can be dimensioned to, and from which the building itself can be dimensioned and located on-site.

What is the main disadvantage of grid layouts? ›

One of the main disadvantages is that grids can make a design feel rigid and inflexible. If designers are too strict in their adherence to the grid, they may find that they are unable to create unique and interesting layouts that stand out from the competition.

How do I display in GridView? ›

A ListView or GridView control must have items in its Items collection before it can display anything on the screen. To populate the view, you can add items directly to the collection or set the ItemsSource property to a data source.

How do you make the gridlines and guides appear? ›

Use static guides and gridlines
  1. Select View > Guides to show the horizontal and vertical center lines.
  2. Select View > Gridlines to show more gridlines.
  3. Use the lines to align objects.
  4. Clear Gridlines and Guides to turn them off.

How do I show grid lines in a photo? ›

For Android Users (Samsung Example)
  1. Open the Camera app.
  2. Tap on the Settings icon (usually a gear icon).
  3. Look for Grid lines and toggle the option on.
Apr 23, 2024

Top Articles
Latest Posts
Article information

Author: Roderick King

Last Updated:

Views: 6365

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Roderick King

Birthday: 1997-10-09

Address: 3782 Madge Knoll, East Dudley, MA 63913

Phone: +2521695290067

Job: Customer Sales Coordinator

Hobby: Gunsmithing, Embroidery, Parkour, Kitesurfing, Rock climbing, Sand art, Beekeeping

Introduction: My name is Roderick King, I am a cute, splendid, excited, perfect, gentle, funny, vivacious person who loves writing and wants to share my knowledge and understanding with you.