0

Hi I want to set tick labels as multiplication of some numbers by 6th power of 10. The problem is that I don't know how to make matplotlib to show it nicely. I do following:

ax.set_yticks([1000000, 1200000, 1400000, 1600000, 1800000, 2000000, 2200000, 2400000])
ax.set_yticklabels([ '1.0*10^6', '1.2*10^6', '1.4*10^6', '1.6*10^6', '1.8*10^6', '2.0*10^6', '2.2*10^6', '2.4*10^6' ], rotation=0, ha='center', va='top')

The effect of above is not what I want to see. I got:

enter image description here

But I would like to have following:

enter image description here

How can I archieve that?

nosbor
  • 2,826
  • 3
  • 39
  • 63

2 Answers2

2

You can use unicode in string:

ax.set_yticklabels([ '1.0∙10⁶', '1.2∙10⁶', '1.4∙10⁶', '1.6∙10⁶', '1.8∙10⁶', '2.0∙10⁶', '2.2∙10⁶', '2.4∙10⁶' ], rotation=0, ha='center', va='top')
macabeus
  • 4,156
  • 5
  • 37
  • 66
1

You need to use math notation. This works as in Latex by enclosing you math expressions with $. It is explained in some detail here.

For your case you could write you strings as:

ax.set_yticklabels([ '$1.0 \cdot 10^6$', '$1.2 \cdot 10^6$',...], rotation=0, ha='center', va='top')
thomas
  • 1,773
  • 10
  • 14