Zorder grid doesn't seem to take effect (matplotlib)

I am trying to plot scatter points on a grid using python matplotlib ( 1.4.3

but also tested other versions with no success). Everything works except the position of the grid zorder

. I set the grid zorder

lower than the value scatter

, but the grid still covers the scatter points.

Here's a simple code to reproduce the problem:

import numpy as np
from matplotlib import pyplot as plt

# create points
pnts = np.array([[1., 1.], [1., 1.2]])

# create figure
plt.grid(True, linestyle='-', color='r', zorder=1)
plt.scatter(pnts[:,0], pnts[:,1], zorder=2)
plt.ylim([0, 2])
plt.xlim([0, 2])
plt.savefig('testfig.png', dpi=350)

      

I get this:
If you zoom in on the dots, you can see the grid is on top, even though it has << 21>: enter image description here

Is this a bug or am I doing something wrong?

+4


source to share


1 answer


If anyone is still curious about this year (as I am), this is a question long ago (September 2015):

Axes.grid () does not honor the given "zorder" kwarg

Quoting the question:

Axes.grid () does not execute the provided custom zorder. Instead, the zorder grid seems to be fixed with some wonderful value between 2.5 and 2.6 (I couldn't find a key for the zorder grid in rcParams).



Apparently the only solution so far is:

just add 2.5 to all your z-orders.

There's also an old answer in this Matplotlib question : draw grid lines behind other graph elements, but it doesn't work anymore.

0


source







All Articles