Decorating the Background Grid in Julia Plots
Overview
Keywords related to the grid background in Plots.jl
are as follows:
Keyword Name | Function |
---|---|
grid | Display grid |
gridalpha , ga , gα | Specify grid transparency |
foreground_color_grid , fgcolor_grid | Specify grid color |
gridlinewidth , grid_lw | Specify grid thickness |
gridstyle , grid_ls | Specify grid line style |
minorgrid | Display minor grid |
minorgridalpha | Specify minor grid transparency |
foreground_color_minor_grid , fgcolor_minorgrid | Specify minor grid color |
minorgridlinewidth , minorgrid_lw | Specify minor grid thickness |
minorgridstyle , minorgrid_ls | Specify minor grid line style |
Code
Display Grid
The keyword for displaying the grid is grid
. Inputting :x
or :y
displays only the lines assisting the $x$ axis or the $y$ axis ticks, respectively. Inputting false
does not display the grid.
plot(plot(rand(10)),
plot(rand(10), grid = :x),
plot(rand(10), grid = :y),
plot(rand(10), grid = false))
Transparency
The grid in the background is drawn with a transparency of 0.1 by default. The keyword for adjusting the grid’s transparency is gridalpha(=ga)(=gα)
.
plot(rand(10, 3), layout = (3, 1),
gridalpha = [0.1 0.5 1])
Color
The default grid color is black, and it can be changed with the keyword foreground_color_grid(=fgcolor_grid)
.
plot(rand(10, 3), layout = (3, 1), gridalpha = 1,
fgcolor_grid = [:red :green :orange])
Thickness
The keyword for specifying the grid thickness is gridlinewidth(=grid_lw)
, with a default value of 0.5.
plot(rand(10, 3), layout = (3, 1),
grid_lw = [0.5 5 10])
Grid Style
The grid line style can be specified with the keyword gridstyle(=grid_ls)
. Possible symbols are :auto
, :solid
, :dash
, :dot
, :dashdot
, :dashdotdot
.
plot(rand(10, 2), layout = 2, ga = 1,
gridstyle = [:solid :dash])
Minor Grid
Inputting the keyword argument minorgrid = true
draws the minor grid. Keywords for specifying the minor grid’s transparency, color, thickness, and line style are minorgridalpha
, foreground_color_minor_grid
minorgrid_lw
, minorgrid_ls
, respectively.
plot(plot(rand(10)),
plot(rand(10), minorgrid = true),
gridalpha = 0.8,
minorgridalpha = 0.2)
Environment
- OS: Windows11
- Version: Julia 1.9.4, Plots v1.39.0