Multiple grids on matplotlib

后端 未结 1 1330
生来不讨喜
生来不讨喜 2021-01-31 20:20

I\'m making plots in Python and matplotlib, which I found huge and flexible, till now.

The only thing I couldn\'t find how to do, is to make my plot have multiple grids.

相关标签:
1条回答
  • 2021-01-31 20:50

    How about something like this (adapted from here):

    from pylab import *
    from matplotlib.ticker import MultipleLocator, FormatStrFormatter
    
    t = arange(0.0, 100.0, 0.1)
    s = sin(0.1*pi*t)*exp(-t*0.01)
    
    ax = subplot(111)
    plot(t,s)
    
    ax.xaxis.set_major_locator(MultipleLocator(20))
    ax.xaxis.set_major_formatter(FormatStrFormatter('%d'))
    ax.xaxis.set_minor_locator(MultipleLocator(5))
    
    ax.yaxis.set_major_locator(MultipleLocator(0.5))
    ax.yaxis.set_minor_locator(MultipleLocator(0.1))
    
    ax.xaxis.grid(True,'minor')
    ax.yaxis.grid(True,'minor')
    ax.xaxis.grid(True,'major',linewidth=2)
    ax.yaxis.grid(True,'major',linewidth=2)
    
    show()
    

    enter image description here

    0 讨论(0)
提交回复
热议问题