I want my y axis to be formatted in scientific notation.
I have tried the matplotlib documentation, but it ignores my command.
import matplotlib.pyplot as plt
import numpy as np
x = np.random.randint(1e4, size=200)
y = np.random.randint(1e4, size=200)
plt.ticklabel_format(axis='both', style='sci')
plt.xlabel('x')
plt.ylabel('y')
plt.scatter(x,y, color='b', s=5, marker=".")
plt.show()
My output just appears in none-scientific notation.
For example I expect the ylabel 1000
to be 1E03
.
This code is just an example.
I have a sub-plot where plot 1 and 3 are in scientific notation, but plot 2 is in non-scientific notation.
Thanks.
You should just add scilimits=(4,4)
to your command
plt.ticklabel_format(axis='both', style='sci', scilimits=(4,4))
for example your code will become:
x = np.random.randint(1e4,size=200)
y = np.random.randint(1e4,size=200)
plt.ticklabel_format(axis='both', style='sci', scilimits=(4,4))
plt.xlabel('x')
plt.ylabel('y')
plt.scatter(x,y, color='b', s=5, marker=".")
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With