0

I was wondering and searching on the docs: is there a way to set the locale, for example, to use commas instead of points as separators for decimals in cartopy ticklabels?

In matplotlib it can be done, but it doesn't apply to cartopy.mpl.ticker's LongitudeFormatter and LatitudeFormatter.

Maybe it's something for the developers to add in newer versions?

haperes
  • 53
  • 10
  • 1
    The gridlines object has a properties 'xformatter' and 'yformatter', which do *have* a 'set_useLocale' method. So I can `gl = ax.gridlines(draw_labels=True)`, then `gl.xformatter.set_useLocale(True)' Have you tried that + it definitely doesn't work ? – pp-mo Nov 16 '17 at 17:44

1 Answers1

1

Nothing too special about the LongitudeFormatter and LatitudeFormatter, they are just specialised Formatters.
So, the gridlines object has properties 'xformatter' and 'yformatter', which have a 'set_useLocale' method.

This worked for me...

>>> ax = plt.gca()
>>> gl = ax.gridlines(draw_labels=True,
...                   xlocs=[-120.5, -50.8, 30.7, 134.2, 157.8])
>>> gl.xformatter.set_useLocale(True)
>>> plt.show()

BUT you do have to have the machine locale set to start with. In order to get "," numeric seperators, I started with :

$ export LC_NUMERIC="it_IT.UTF-8"
$ python

I don't know much about it, but I think you can't change this dynamically through the Python interface, it needs to be in the calling environment
-- see Setting Python locale doesn't work

pp-mo
  • 468
  • 2
  • 8
  • It works for the comma, but I'm not using `ax.gridlines`, and I don't want the gridlines themselves. I'm using `ax.set_yticks` and then `LongitudeFormatter` and `LatitudeFormatter` to have the °, W and S written in the ticklabels – haperes Nov 17 '17 at 21:53