I am created a set of subplots, and I want to show light gray minor grid lines on my log y-axis. This code works for some of the plots, but not all. I can't figure out why it doesn't work for all plots.
It seems to be somewhat related to the plot title; if I comment it out, 11 of the 12 plots are correct.
I want to keep the 'seaborn-whitegrid' plot style, just with this modification of adding the minor grid lines to the y-axis.
import matplotlib.pyplot as plt
%matplotlib inline
from matplotlib.ticker import ScalarFormatter
plt.style.use('seaborn-whitegrid')
fig, axes = plt.subplots(3,4, figsize=(8.5,5.5), constrained_layout=True)
counter = 0
for ax in axes.flat:
id1 = mysummary.id1[counter]
df_subset = df[df.ID == id1]
ax.hist(df_subset.x, density=False,
edgecolor='black', color='lightgray',
cumulative=False, orientation='vertical')
ax.set_title('my long \n title', fontsize=8)
ax.set_xlabel('x', fontsize=8)
ax.set_ylabel('Count', fontsize=8)
ax.set_yscale('log')
ax.set_ylim(ymin = 1)
ax.set_xlim(xmin = 0)
ax.grid(b=True, which='minor', axis='y', color='#999999', alpha=0.2)
ax.yaxis.set_major_formatter(ScalarFormatter(useOffset=False))
ax.locator_params(axis='x', nbins=4)
ax.xaxis.set_tick_params(labelsize='small')
ax.yaxis.set_tick_params(labelsize='small')
counter += 1