Search code examples
plotcolorsgridjulia

Color grid lines in Julia


I would like to color the grid lines in a plot. Here is some reproducible code:

using Plots
Plots.plot(rand(10))

Output:

enter image description here

Imagine I want to have green grid lines, how can we change the color of grid lines in Julia? I check the docs, but I can only find attributes like alpha, line width and style and not the color.


Solution

  • Here is some code to get the green grid:

    plt = Plots.plot(rand(10))
    xaxis = Plots.get_axis(Plots.get_subplot(plt,1),:x)
    yaxis = Plots.get_axis(Plots.get_subplot(plt,1),:y)
    xaxis[:gridalpha] = 0.6
    yaxis[:gridalpha] = 0.6
    xaxis[:foreground_color_grid] = colorant"green"
    yaxis[:foreground_color_grid] = colorant"green"
    plt
    

    Many other attributes are described in the docs page you linked to.