Issue
I have a problem with this plot:
The y-axis is in unit but I need them to be in millions as such:
Do you know a method to achieve this? Thanks in advance.
Solution
You can use a custom FuncFormatter like this:
from matplotlib.ticker import FuncFormatter
import matplotlib.pyplot as plt
def millions(x, pos):
'The two args are the value and tick position'
return '%1.1fM' % (x * 1e-6)
formatter = FuncFormatter(millions)
fig, ax = plt.subplots()
ax.yaxis.set_major_formatter(formatter)
Or you can even replace millions with the following functions to support all magnitudes:
def human_format(num, pos):
magnitude = 0
while abs(num) >= 1000:
magnitude += 1
num /= 1000.0
# add more suffixes if you need them
return '%.2f%s' % (num, ['', 'K', 'M', 'G', 'T', 'P'][magnitude])
Answered By - Bogdan Veliscu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.