5

I'm trying to control the number of tick marks on my graphs using locator params. I want a graph that has five vertical lines plus the two edges of the graphs (ie 7 values total on the x and y axes).

I've been using locator params and trying to set nbins = 7, but that doesn't work. Unless I use extreme values, like nbins = 12 or nbins = 3, nothing changes on my graphs and I don't understand why.

Here is some of my code:

    gs1 = gridspec.GridSpec(3,3)
    ax6 = plt.subplot(gs1[-1,-1])
    q=np.arange(79.9,80.1,1e-4)
    ax6.plot(q, np.exp(-((q-80)**2)/(2*sig_gauss[2]**2)),'k')
    ax6.grid()
    ax6.locator_params(axis = 'y',nbins=7)
    ax6.locator_params(axis = 'x',nbins=7)
    ax6.set_xlim(79.9,80.1)

I don't understand why changing the number of nbins only works sometimes.

pelkat
  • 71
  • 5
  • If anyone is interested in knowing the answer, I figured out a way that works. using np.lispace creates the right number of bins. I used ax6.set_yticks(np.linspace(0,1,7)) – pelkat Jun 24 '16 at 17:15
  • You can answer your own question. If you expand your comment into an answer, you can get upvotes. – Bernhard Aug 31 '16 at 10:00

1 Answers1

0

If anyone is interested in knowing the answer, I figured out a way that works. using np.lispace creates the right number of bins. I used

ax6.set_yticks(np.linspace(0,1,7))
miken32
  • 42,008
  • 16
  • 111
  • 154
pelkat
  • 71
  • 5
  • The key part of the suggestion was "If you *expand* your comment into an answer..." Maybe a link to relevant documentation, or an explanation of why it worked for you. – miken32 Aug 31 '16 at 17:15