Matplotlib add gridlines not working as expected

二次信任 提交于 2021-01-29 15:41:53

问题


Using matplotlib subplots() in Jupyter Notebook, and using "seaborn-whitegrid" plot.style().

I am trying to add minor gridlines to my x-axis, which is in log.

What am I missing?

import matplotlib.pyplot as plt
%matplotlib inline 
plt.style.use('seaborn-whitegrid')

x, y = [(1, 9, 65, 142, 330), (0, 0.16, 0.50, 0.84, 1)]
fig, axes = plt.subplots(3,5, figsize=(8.5,5.5), constrained_layout=True)

#counter = 0
for ax in axes.flat:
    ax.plot(x,y)
    ax.set_title('Dataset-A', fontsize=8)
    ax.set_xlabel('x', fontsize=8)
    ax.set_ylabel('CFD', fontsize=8)
    ax.set_xscale('log')
    ax.set_xlim([1, 1000])
    ax.set_ylim([0, 1])
    ax.grid(True, axis='both', which='minor', color='red')

    #counter += 1 ##will use to iterate through real dataset

来源:https://stackoverflow.com/questions/65727726/matplotlib-add-gridlines-not-working-as-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!