Menu

#2760 How to get grid to front?

None
closed-not-a-bug
nobody
2025-01-15
2025-01-15
theozh
No

It seems a simple task cannot be realized although gnuplot offers several options:

How to bring the grid in front of the key/legend?
(let's aside whether the grid through the legend helps readability)
(triggered by this question: https://stackoverflow.com/q/79357685)

  1. most obvious: set grid front
    The legend does still white out the grid around the area of the legend

  2. additionally: set key noopaque
    key still isn't transparent, what you would expect

  3. additionally: set term pngcairo transparent background
    Ususally, key box is filled with background color, but setting transparent background color doesn't seem to work

  4. set key fc rgb 0xff123456
    transparent color to fill the legend box doesn't seem to work

Tested with Windows10 gnuplot 6.0.2
Just for better visibility of the issue: set grid lt -1

Script:

### how to bring grid to front?
reset session

set xtics 1
set mytics 2
set grid x,y,mx,my front lt -1
set key font ",16" noopaque

plot sin(x), cos(x)
### end of script
1 Attachments

Discussion

  • Ethan Merritt

    Ethan Merritt - 2025-01-15

    1) 2)
    The key area is intentionally reserved so that the grid will not obscure the key contents. When grid lines are drawn, they are clipped against the key area. So it doesn't matter whether the grid is in front or in back; either way it will not obscure the key. That was a design decision made sometime last century, prior to version 3.7.

    3)
    You can use the terminal background as a fillcolor for at least some terminal types, as in the sequence below.

    set term wxt background "cyan"
    set obj rect behind from graph 0,0 to graph 1,1 fillcolor "white"
    set key opaque fillcolor background
    plot sin(x)
    

    It may be true that the pngcairo terminal doesn't store an alpha channel for the background color (I haven't looked into that) but if so that doesn't really have anything to do with the key area.

    4)
    The command is set key opaque fillcolor <whatever>

     
  • theozh

    theozh - 2025-01-15

    Thanks, Ethan! So, in summary: it is not intended to put the grid in front of the legend. Actually, it is prevented by design.

     
  • Ethan Merritt

    Ethan Merritt - 2025-01-15
    • status: open --> closed-not-a-bug
    • Group: -->
    • Priority: -->
     

Log in to post a comment.