def ticklabels_to_thousands_sep(ax, axis='y'): getattr(ax, '{}axis'.format(axis)).set_major_formatter( mticker.FuncFormatter(lambda s, position: '{:,}'.format(int(s)))) return ax