Skip to content

Instantly share code, notes, and snippets.

@unutbu
Created November 2, 2018 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unutbu/44fb0517c214a2779b4c36d718badea4 to your computer and use it in GitHub Desktop.
Save unutbu/44fb0517c214a2779b4c36d718badea4 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.ticker as ticker
img = np.random.randn(300,300)*10**-6
myplot = plt.imshow(img)
def fmt(x, pos):
a, b = '{:.2e}'.format(x).split('e')
# x = a * 10**b = a * 10**(b-1) * 10**1
a = float(a)
b = int(b)
return r'${:.10f} \times 10^{{{}}}$'.format(a * 10**(b-1), 1)
plt.colorbar(myplot, format=ticker.FuncFormatter(fmt))
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment