0

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

enter image description here

Mr. T
  • 11,960
  • 10
  • 32
  • 54
a11
  • 3,122
  • 4
  • 27
  • 66
  • 1
    When running your code verbatim, I see gridlines as well as as different x-axis with 10 to the ) to 10 to the4 3. What version are you on? – David Erickson Jan 14 '21 at 22:23
  • 1
    @DavidErickson even with `plt.style.use('seaborn-whitegrid')`? – a11 Jan 14 '21 at 22:24
  • 1
    yes, I am seeing a different image than what you are showing. `'0.11.1'` is my seaborn version. `'3.1.3'` is my `matplotlib` version. You can use `sns.__version__` and `matplotlib.__version__`. Make sure to do just `import matplotlib`. What is your version? – David Erickson Jan 14 '21 at 22:25
  • wow, any idea why that would happen? I just shut down notebook, restarted, started new notebook and I see same plot as I show above – a11 Jan 14 '21 at 22:26
  • Similar to David not reproducible here. Does the same happen in your environment outside Jupyter Notebook or not? Most likely some setting there that causes this behavior. – Mr. T Jan 14 '21 at 22:57
  • @Mr.T yes, it does happen outside Notebook in this environment. I also tried it in the default Anaconda environment and it happens there too. Both are Python 3x. I ran it in a Python 2.7 (install not from Anaconda) and it worked correctly. Bummer, the environment-based problem seems tougher to fix. Thanks all for the independent tests – a11 Jan 15 '21 at 00:06
  • Well this is an annoying solution, but it works: `y_minor = matplotlib.ticker.LogLocator(base = 10.0, subs = np.arange(1.0, 10.0) * 0.1, numticks = 10)` ... `ax.xaxis.set_minor_locator(y_minor)` ... `ax.grid(True, axis='x', which='minor', color='red')` ... from 2nd answer by user "zyy" here https://stackoverflow.com/questions/30887920/how-to-show-minor-tick-labels-on-log-scale-with-matplotlib – a11 Jan 15 '21 at 00:10

0 Answers0