Matplotlib: keep grid lines behind the graph but the y and x axis above

前端 未结 4 684
孤街浪徒
孤街浪徒 2021-01-02 01:18

I am having a hard time plotting grid lines under my graphs without messing with the main x and y axis zorder:

import matplotlib.pyplot as plt
import numpy a         


        
4条回答
  •  忘掉有多难
    2021-01-02 02:22

    A easier and better solution is to copy the lines from the grid command and disable the grid and again add the lines again but with correct zorder:

    ax.grid(True)
    lines = ax.xaxis.get_gridlines().copy() + ax.yaxis.get_gridlines().copy()
    ax.grid(False)
    for l in lines:
        ax.add_line(l)
        l.set_zorder(0)
    

提交回复
热议问题