How Can I Change The X-axis Labels In A Python Plot?
I have this code : import numpy as np import pylab as plt a = np.array([1,2,3,4,5,6,7,8,9,10]) b = np.exp(a) plt.plot(a,b,'.') plt.show() The code works fine, but I need to modi
Solution 1:
import numpy as np
import pylab as plt
a = np.array([1,2,3,4,5,6,7,8,9,10])
# this is it, but better use floats like 10.0,
# a integer might not hold values that big
b = 10.0 ** a
plt.plot(a,b,'.')
plt.show()
Solution 2:
This code probably is what you need:
import numpy as np
import pylab as plt
a = np.asarray([1,2,3,4,5,6,7,8,9,10])
b = np.exp(a)
c = np.asarray([10**i for i in a])
print(list(zip(a,c)))
plt.xticks(a, c)
plt.plot(a,b,'.')
plt.show()
By using plt.xtick()
you can customize your x-label of plot. I also replaced 10^i
with 10**i
.
Post a Comment for "How Can I Change The X-axis Labels In A Python Plot?"