Graph grid GRID command¶
Commands in this namespace document the graph grid.
GRID is used below as a placeholder for:
GRAPHINST grid
The grid draws horizontal and vertical lines across the plotting area at axis tick positions.
The grid follows the graph’s -renderer and -antialias settings. Cairo preserves its axis mappings,
major/minor tick selection, dash pattern, and color. A zero -linewidth remains a one-pixel hairline.
Grid labels and all other text remain native.
For example:
graph .g
.g grid configure -hide no -color grey70 -dashes dot
The grid is a single component of the graph. Unlike elements, markers, or pens, there are no named grid objects.
Grid axes¶
-mapx and -mapy select the axes whose tick positions are used to generate the grid.
-mapx controls the vertical grid lines:
.g grid configure -mapx x
-mapy controls the horizontal grid lines:
.g grid configure -mapy y
Either mapping may be empty to disable grid lines for that direction:
.g grid configure -mapx {}
This is especially useful for bar charts, where the default grid uses only the Y axis.
The axis names refer to graph axes documented by AXIS.
Major and minor grid lines¶
Grid lines normally follow both major and minor axis ticks.
The -minor option controls whether lines are also drawn at minor tick positions:
.g grid configure -minor no
With -minor no, only major tick positions generate grid lines. With -minor yes, minor tick positions are
included as well.
The number and spacing of the grid lines therefore depend on the tick configuration of the mapped axes.
Showing and hiding the grid¶
The -hide option controls grid visibility:
.g grid configure -hide no
The GRID on, GRID off, and GRID toggle operations provide convenient alternatives:
.g grid on
.g grid off
.g grid toggle
These operations change the same state represented by -hide. For example, after:
.g grid off
querying:
.g grid cget -hide
returns a true value.
Widget-specific defaults¶
The initial grid configuration depends on the graph widget type.
Widget |
|
|
|
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
empty |
|
Thus a graph or stripchart does not initially display its grid, while a barchart initially displays
horizontal grid lines associated with its Y axis.
The remaining grid defaults are common to all graph widget types.
Grid options¶
Option |
Database name |
Database class |
Description |
|---|---|---|---|
|
|
|
Sets the color used to draw grid lines. The default is grey64, or black on monochrome displays. |
|
|
|
Sets the dash pattern used to draw grid lines. An empty value selects solid lines. The default is |
|
|
|
Controls whether the grid is displayed. The default is |
|
|
|
Sets the non-negative width of grid lines. Values |
|
|
|
Specifies the X axis whose ticks generate vertical grid lines. The axis must exist and must be an X axis. An empty value disables X grid lines. The default is |
|
|
|
Specifies the Y axis whose ticks generate horizontal grid lines. The axis must exist and must be a Y axis. An empty value disables Y grid lines. The default is |
|
|
|
Controls whether grid lines are also generated at minor tick positions. The default is |
Grid configuration options may also be supplied through Tk’s option database. The resource name is grid and
the resource class is Grid.
For example:
option add *Graph.grid.Color grey70
option add *Graph.Grid.Linewidth 1
Copyright (c) George Yashin