1

I am using Matplotlib to plot a 3*4 subplots. I am going to change the style of tick label to 'sci' so that the plotting can be more neat. But using the following code, the ticklabel_format do not even take effect on the axis.

import matplotlib.pylab as pl

fig, axes = pl.subplots(nrows=3, ncols=4)

for i,row in enumerate(axes):
    for j,ax in enumerate(row):
        ax.set_title('title')
        ax.ticklabel_format(styl='plain')

pl.tight_layout()
pl.show()

I have intently make a typo 'styl', but it doesn't report error. So I assume the ticklabel_format function doesn't even run.

Hello lad
  • 17,344
  • 46
  • 127
  • 200
  • 1
    What is `pl`? Is it `mpl`? – j-i-l Aug 20 '14 at 22:36
  • I'm pretty sure this code won't work, at all, unless you import pyplot (which is *probably* what you meant by `pl`). Make sure when you post code that it really does what you think it does - direct copy/pasting is best. – Ajean Aug 21 '14 at 00:07
  • @jojo, thank you for your comment. It is matplotlib.pyplot, I have reedited. – Hello lad Aug 21 '14 at 08:00

1 Answers1

0

It not taking effect because ax.ticklabel_format takes any keyword argument and creates a dictionary. To see this take a look at the documentation here and you will see it takes an argument **kwargs. If you just replace styl with style then your code will work.

I suggest you take a look at this SO post to get a feel of what was going wrong but in brief: the function can take any argument. It then attempts to pass these on to other functions. If none of these require it then the argument is simply lost in the ether. As a result there is no error message!

Try playing around with the following example to get a feel **kwargs.

def f(**kwargs):
    print kwargs
    return

f(anything='something')
Community
  • 1
  • 1
Greg
  • 11,654
  • 3
  • 44
  • 50