Related to Matplotlib: draw grid lines behind other graph elements, but nothing there worked for me.
I have the following plot where I want to hide the gridlines under the red line while retaining the labels on top of the red line:
import numpy as np
import matplotlib.pyplot as plt
#plot
r = np.arange(0, 3.0, 0.01)
theta = 2 * np.pi * r
ax = plt.subplot(111, polar=True)
ax.plot(theta, r, color='r', linewidth=20)
ax.set_rmax(2.0)
ax.grid(True, lw=2)
#set labels
label_pos = np.linspace(0.0, 2 * np.pi, 6, endpoint=False)
ax.set_xticks(label_pos)
label_cols = ['Label ' + str(num) for num in np.arange(6)]
ax.set_xticklabels(label_cols, size=24)
I can get the red line on top with ax.set_axisbelow(True)
.
But I can't find a way to keep the red line on top of the gridlines while retaining the labels on top of the red line. Adding zorder=-1
to the plot command, puts the red line in the bottom even if I add ax.set_axisbelow(True)
. ax.set_zorder(-1))
has not worked so far either.
How can I get the grid lines in the bottom (lowest zorder) followed by the red line and then the labels on top of the red line?